Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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

share|improve this question

2 Answers 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.

share|improve this answer

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.