0

I expect this script to switch applications (command tab):

$ cat hello.applescript
tell application "System Events"
 key code 48 using command down
end tell

But it just prints out a tab:

$ osascript hello.applescript
⏎   

I'm on OS X 10.9.4

1

I've not used it inside a shellscript, only in 'pure' Applescript, but why not just

tell application "myApp" to activate

..it would prevent the randomness of which particular app was next in line.

1

According to this you need to tell Finder as well:

tell application "System Events"
  tell process "finder"
    activate
    keystroke tab using {command down}
  end tell
end tell

But I also like the suggestion to specify the app by name...

  • mhm - I'm pretty sure that the launch order of apps on that particular day is going to jump up & bite someone in the soft parts at some point, if the required app is not specified. – Tetsujin Aug 30 '14 at 10:44
  • @Tetsujin - I agree, and prefer your solution in the long run. I was curious why the command wouldn't work as stated, and this appears to be the reason. – beroe Aug 30 '14 at 14:39
  • Thanks. Just to be clear, I'd like to simulate keypresses exactly. You see the same issue when you replace tab with "T". My goal wasn't to script this command or that, but to script general keystrokes. – sam boosalis Aug 30 '14 at 19:32
  • If you can explain the difference in your question, and which app you want to simulate them for, we might be able to give a more specific response. – beroe Sep 1 '14 at 3:52

You must log in to answer this question.

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