0

Is it possible to invoke a keyboard shortcut from applescript?

For example I like to run the F11 keyboard shortcut.

MrU
  • 592
William
  • 1,658

2 Answers2

0

Do you mean open the applescript from keyboard shortcut? if so, then follow this to convert the applescript into an app, then create a Service using Automator.

Hope this helps.

MrU
  • 592
  • For example I have "Show Desktop" set to f11 key. I would like to invoke the f11 key for AppleScript. – William Feb 10 '15 at 00:59
  • Like I mentioned in my answer. You cannot open files with a keyboard shortcut like on Windows, but on Mac it'll open Apps. Therefore you have to convert the AppleScript to an app, then create a keyboard shortcut service. From then the keyboard shortcut should be accessible anytime. – MrU Feb 11 '15 at 01:46
  • Small typo "I would like to invoke keyboard shorcut from AppleScript" I have left a response that works. – William Feb 11 '15 at 03:03
0

The following works from the terminal.

osascript -e "tell applications \"System Events\"" -e "key code 100" -e "end tell"

Alternatively I believe this should work.

tell application "System Events"
    key code 101
end tell

Googling mac osx system events key code should bring up several options.

William
  • 1,658