Re: Running AppleScripts from Users CronTab
Re: Running AppleScripts from Users CronTab
- Subject: Re: Running AppleScripts from Users CronTab
- From: Andrew Oliver <email@hidden>
- Date: Wed, 16 Nov 2005 12:00:55 -0800
On 11/16/05 10:55 AM, "Doug McNutt" <email@hidden> wrote:
> At 08:45 -0800 11/16/05, Christopher Nebel wrote:
>> In general, AppleScript does not work well with no logged-in user, or from
>> outside the currently logged-in user's "space" -- some of it has to do with
>> historical baggage, some of it has to do with fundamental restrictions (if
>> there's no one logged in, you aren't allowed to launch applications, which
>> restricts AppleScript dramatically).
>
> That deserves a whole lot of expansion. Are the rules hiding somewhere in the
> Apple Documentation?
>
> What if I telnet to my Mac? Does that count as being logged in?
Logged in, yes. Attached to the WindowServer? No.
> Does osascript work?
No comment ;)
> Does it work but with the caveat that it can't "tell" any applications?
> Can it tell an application that happens to be open and running by an
> AQUA-logged-in user?
If you are logged in via telnet (or SSH, right?), AND you are also logged in
on the GUI, then yes, osascript can run and do everything you want. However,
if any other user (or no user) is logged in at the desktop then you cannot
use osascript to run an AppleScript unless you run osascript via sudo/as
root.
> Can a cron job using osascript assume that Finder is running at all times?
IMHO, no process, ever can assume that the Finder is running. You certainly
can't assume that in your osascript and most certainly can't assume that
when launched via cron.
Heck, even if your script is a .app bundle you can't assume that the Finder
is running. Of course, 99.9% of the time when running in the GUI, the Finder
is there, but it doesn't *have* to be.
> Can I "tell Finder" from a session initiated with a telnet login?
Not unless you're also the user running the Finder in a WindowServer
session. (IIRC there was an issue where user A could control the Finder
running for user B, where user A's script could make changes to user B's
setup, but I seem to recall that was fixed a while ago, no?)
>Does osascript work in single user mode?
Is there a WindowServer in single user mode? No. There's your answer.
> If I am logged in as an AUQU user and I telnet from elsewhere can I access -
> kill for instance - jobs that were started from AQUA with commands from the
> telnet session. Assume it's the same username.
Yes. You can even kill other user's processes if you have sufficient
privileges.
> Can the original poster open an application in background from a telnet
> session and then close the session. Will it remain available to a later cron
> job (same user) that needs it?
That depends on how the process was launched and whether it stays running
after the shell exists (e.g. a daemon or backgrounded process). Normally
when you exit the shell all processes you launched quit, too.
>
> Can an AQUA application be started by something like a login hook so that it
> will remain available to cron jobs?
Only as long as the user whose login hook starts the process stays logged
in, and that user is the same user whose crontab is trying to interact with
it.
In summary, there are so many caveats I go along with Chris' suggestion -
don't try to use osascript/AppleScript via cron. Use a shell script instead.
If you need timed events to run while a user is logged in, there are other
ways of achieving that which don't use cron (and that way they don't try to
run when the user isn't logged in).
Andrew
:)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden