paulr
paulr

Reputation: 203

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'

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"'

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.

Upvotes: 5

Views: 2597

Answers (1)

epetousis
epetousis

Reputation: 454

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.

Upvotes: 1

Related Questions