osascript login/logout scripts fail when run on Lion via ssh

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.

Posted on Sep 28, 2011 11:11 AM

Reply
4 replies

Sep 28, 2011 6:12 PM in response to Paul Robichaux

I would be very surprised if such scripts worked reliably in any version of MacOS X. To perform those operations, you need a logged in session that ssh does not fully provide. It may work if you are already logged in and also running ssh. Maybe not. Also, from your description, you say it does work when run as a compiled script. So what's the problem?


Can you explain what you are actually trying to accomplish, at a high level?

Sep 28, 2011 8:18 PM in response to etresoft

I assure you that the scripts work reliably; we've been using them daily for more than a year at two sites in the US. The scripts themselves are based on scripts that other folks have apparently been using for a while.


Anyway, that aside, what we're doing is using these scripts as part of a software distribution and update system for our application. For reasons that are too boring to go into, but which involve Java, we can't repackage the app into a more Mac OS X-friendly distribution format. The fact that these scripts don't work as written in Lion is breaking our update and distribution process.


While running with compiled scripts might solve the problem, it doesn't explain what caused the problem in the first place, which is what I was originally asking.

Sep 28, 2011 10:34 PM in response to Paul Robichaux

You haven't really given enough information to diagnose the problem thoroughly. I mean, it's clear that what's happening is that the scripts are failing to compile correctly - whenever you see a keyword being treated as a variable (variable 'out' is not defined) it means that the app's scripting dictionary hasn't been loaded. that could happen for a number of reasons:

  • you've logged into an account that has some sort of security restriction
  • you've logged into an account that has no access to the core services apps
  • you've run into a bug or a race condition
  • etc.

My guess would be that Lion tightened up some security policy that makes this behavior no longer work (intentionally or unitentionally). Know way to know without puddling around.

Sep 29, 2011 5:40 AM in response to Paul Robichaux

Paul Robichaux wrote:


I assure you that the scripts work reliably


Sure doesn't sound like it. Otherwise, they would continue to work.


The scripts themselves are based on scripts that other folks have apparently been using for a while.


That doesn't mean they were ever correct to begin with. There are many solutions that work, yet are still wrong. One symptom of this is when they mysteriously fail.


Anyway, that aside, what we're doing is using these scripts as part of a software distribution and update system for our application. For reasons that are too boring to go into, but which involve Java, we can't repackage the app into a more Mac OS X-friendly distribution format.


I do this stuff for a living, so it isn't boring to me. Is this a solution you are selling to people in a lab environment? Or is this a solution you've developed for your own lab environment? I would still like to know exactly what you are doing with this scripts - at a high level. Obviously you want something to happen at login and logoff. What kind of login or logoff? ssh, Aqua, X, or what? What, specifically, do you want to happen?


The fact that these scripts don't work as written in Lion is breaking our update and distribution process.


While running with compiled scripts might solve the problem, it doesn't explain what caused the problem in the first place, which is what I was originally asking.


My theory is your scripts were never a valid solution to begin with. Compilation and execution of an AppleScript sometimes requires an active Aqua session. When it does and doesn't require that is not well defined and could very well change between OS versions. In virtually all cases, there are other solutions that will perform the same task without a dependency on an Aqua login session. Without knowing what you are really trying to do, I can't do any speculation more accurate than that.


It seems to be a moot point. For whatever reason, the scripts don't work anymore. Perhaps it is a bug in Lion, perhaps not. I don't know without more details. If it is a bug in Lion, you can write a bug report and maybe get it fixed in a year or two. Or, you could just fix the scripts. Or, you could just drop the Mac version. All I can do is help you fix the scripts.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

osascript login/logout scripts fail when run on Lion via ssh

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.