2

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).

2

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:

tell application "System Events"
    tell application "Microsoft Entourage" to activate
    tell menu "Edit" of menu bar item "Edit" of menu bar 1 of process "Microsoft Entourage"
        click menu item "Select All"
        click menu item "Copy"
    end tell
    key code 123
end tell

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.

1

For example, you can do :

tell application "System Events"
    keystroke "c" using command down
    keystroke "v" using {option down, command down}
end tell

To press : cmd+C and then cmd+alt+V

You must log in to answer this question.

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