user1964918
user1964918

Reputation: 41

execute a keyboard shortcut using apple script in automator

im using apple script in automator for the first time. i want the script to execute a keyboard shortcut within a previously launched application.

on run
activate application "MacCaption"
tell application "MacCaption"
    keystroke "x" using command down

end tell

Im getting Syntax Error expected end of line but found identifier on the word using.

Upvotes: 4

Views: 5856

Answers (2)

tkbx
tkbx

Reputation: 16275

Your problem is that keystroke has to go through System Events. Either:

tell app "System Events"
    keystroke "x" using command down
end tell

or

tell app "System Events"
    tell process "MacCaption"
        keystroke "x" using command down
    end tell
end tell

There's no real difference, but you need the System Events.

Upvotes: 3

adayzdone
adayzdone

Reputation: 11238

Try:

tell application "System Events" to keystroke "x" using command down

Upvotes: 1

Related Questions