I need to invoke a keyboard shortcut from within an AppleScript code, later to be used as a startup item (i.e. the alternative to having to press something at every log in).
How to one invoke a keyboard shortcut from within an AppleScript
applescriptkeyboard
Related Question
- MacOS – Applescript Won’t Invoke Shortcut Command
- MacOS – How to make selection from AppleScript dialog list with keystroke
- MacOS – How to rework a “System Events” command in AppleScript, so that it automatically works in all applications
- MacOS – Keyboard shortcut for AppleScript works only when preferences window is open
- Keyboard shortcut in finder to launch >share via>airdrop
Best Answer
I get the impression that what you're trying to do is a copy command (i.e., ⌘C)—am I right?
Here's an example from one of my scripts:
That is, I script the menu command instead of scripting shortcuts.
You might also take a look and see if you have
/Library/Scripts/UI Element Scripts/Key Down-Up.applescript
, which should give you alternate ideas of how to emulate keyboard actions.And of course, there are a lot of examples in
/Library/Scripts/
and~/Library/Scripts/
, many of which are worth a look in general.