Is it possible to invoke a keyboard shortcut from applescript?

For example I like to run the F11 keyboard shortcut.


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.

| improve this answer | |
  • 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 0: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 1:46
  • Small typo "I would like to invoke keyboard shorcut from AppleScript" I have left a response that works. – William Feb 11 '15 at 3:03

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.

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .