MacOS – Applescript code to simulate Command and Shift keys

applescriptkeyboardmacosvoice-dictation

I am handicapped and use Dragon Dictate 3. I need to take control of my Mac with Dragon, because I am not be able to use the keyboard. I need to know some Applescript code to do that.

How could I simulate the pressing of the Command key and the Shift key to select multiple items in Finder?

First of all, Thanks to adayzdone for his solution.

I tested these with some success. So let me give it to you for helping other user which are experiencing problems.

1) locking Command key on Dragon dictate 3 procedure.

Name of the command (in french) : " Vérrouillage Touche Commande ". Method : Applescript Context : Finder

set _dictateApp to (name of current application)
    tell application "System Events"
        tell process "Finder"
            command key down
        end tell
    end tell

2) unlocking Command key on Dragon dictate 3 procedure.
Name of the command (in french) : " Dévérrouillage Touche Commande ". Method : Applescript Context : Finder

set _dictateApp to (name of current application)
    tell application "System Events"
        tell process "Finder"
            command key up
        end tell
    end tell

3) multiples selections of items in Finder on Dragon dictate 3 procedure.
Method : Applescript Context : Finder

set _dictateApp to (name of current application)
tell application _dictateApp
  set bundleID to («property BnID» of «property cCtX»)
end tell
set _currentAppName to short name of (info for (path to application id bundleID as alias))
try
  tell application "System Events"
    tell process _currentAppName
      key code 125 using {shift down}
    end tell
  end tell
end try

AND/OR in another command

set _dictateApp to (name of current application)
tell application _dictateApp
  set bundleID to («property BnID» of «property cCtX»)
end tell
set _currentAppName to short name of (info for (path to application id bundleID as alias))
try
  tell application "System Events"
    tell process _currentAppName
      key code 126 using {shift down}
    end tell
  end tell
end try

Hope it will help.
Thanks to all
Claude

Best Answer

Briefly looking at the Dragon Dictate manual: enter image description here

A script like this will let you select the next item of a Finder window:

--key code 126 -- up arrow Key
--key code 125 -- down arrow Key

activate application "Finder"
tell application "System Events"
    key code 125 using shift down
end tell