keystroke command not working

tell application id "org.galad.Subler"
	launch
	activate
	keystroke "n" using command down
end tell

When I run this I get an error saying “Syntax Error - Expected end of line, etc. but found identifier.” and it highlights the word “using”.

Hi,

I don’t know Subler, but it seems there is no keystroke command in its dictionary.

Normally keystroke belongs to System Events.
The syntax is something like this


activate application id "org.galad.Subler"
tell application "System Events"
	tell process "Subler" -- the name of the process could be different
		keystroke "n" using command down
	end tell
end tell

command n creates a new interface window. It’s listed in the menu.

Yes, but we’re talking about the AppleScript command keystroke, not the menu action

I thought it could do menu commands via the keystroke.

Yes, it can, but the app needs a keystroke command in the AppleScript dictionary.

System Events has got one, Subler obviously not.

Sending keystrokes is a part of GUI scripting, System Events is the designated app for it

Browser: Safari 536.26.17
Operating System: Mac OS X (10.8)

Okay, so I guess Subler is not scriptable. Thanks.

Hello.

What StefanK said, was that if you did like he showed you, then it would work, provided that you have UI scripting enabled, that is you have to enable access for assistive devices in System Preferences.

Yes, but I guess I can’t expect other people who use the script to have that turned on. Thanks for the clarification.

You don’t exepct it, you just turn it on!

it goes something like this:


tell application "SystemEvents" to set UI elements enabled to true

You’ll have to look it up in the dictionary, I am writing it from memory.

okay thanks. I’ll give that a try.

System Events’s ‘keystroke’ should work whether GUI Scripting’s enabled or not, unless it’s changed since Snow Leopard. All that’s required is for the process receiving the keystroke to be frontmost.

I got it to work with this:

tell application "System Events"
	set UI elements enabled to true
	activate application id "org.galad.Subler"
	keystroke "n" using command down
end tell

Thanks for the help!

Now that is nice to know! Typing must be avoided at all cost! I thought it really was part of the assistive devices.