Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do simple osascript commands fail in OS X Lion?

I have two very simple OSA scripts to allow logon and logoff of computers in a lab environment. These scripts work flawlessly in Snow Leopard when pushed via ARD, interactively within an ssh session, but they fail on machines running Lion.

Stripped down to its essentials, the logout script looks like this:

osascript -e 'tell application "System Events" to log out'

  • WORKS when run directly from an interactive shell on a machine
  • WORKS when pushed from ARD
  • FAILS with "execution error: The variable out is not defined. (-2753)" when run from an ssh session
  • WORKS when the script is compiled to an .scpt, then run from ssh (e.g. "/usr/bin/osacript logout.scpt")

The login script is directly based on this. A stripped-down version that exhibits the problem is:

osascript -e 'tell application "System Events" to keystroke "frontend"'

  • WORKS when run directly from an interactive session
  • WORKS when pushed from ARD
  • FAILS with execution error: An error of type -10810 has occurred. (-10810) when run from ssh
  • WORKS when run as a compiled scpt and run from ssh

Because these scripts work fine interactively, and because they worked fine in all modes in Snow Leopard, I think something must have changed in osascript, but I don't know what, and the error messages aren't very descriptive. Any suggestions would be welcome.

like image 373
paulr Avatar asked Nov 13 '22 16:11

paulr


1 Answers

Try escaping the quotes.

So: osascript -e 'tell application "System Events" to log out' becomes: osascript -e 'tell application \"System Events\" to log out'

And osascript -e 'tell application "System Events" to keystroke "frontend"' becomes: osascript -e 'tell application \"System Events\" to keystroke \"frontend\"'

Give that a go and tell us what happens.

like image 105
epetousis Avatar answered Dec 06 '22 08:12

epetousis