Re: user interaction (& osascript/cron & System Events )
Re: user interaction (& osascript/cron & System Events )
- Subject: Re: user interaction (& osascript/cron & System Events )
- From: Steven Majewski <email@hidden>
- Date: Tue, 22 Jun 2004 15:13:00 -0400
Another way around the cron & osascript user interaction limitation
seems to be to use NSAppleScript to run the script.
You need pyobjc extensions installed.
You need to use pythonw (from the application bundle, not python)
( If you run it with /usr/bin/python, you'll get the same 'No user
interaction' error
you get with osascript' )
You need to provide a .applescript source file, not a compiled .scpt.
With the following python code as 'astest.py', you can run:
$ batch
pythonw astest.py my.applescript
-- or add it to your crontab file.
-- Steve Majewski
##
## astest.py
##
src = defsrc = """
tell me
activate
display dialog "TESTING..."
end tell
"""
import sys,os
from Foundation import NSAppleScript,NSString
as=NSAppleScript.alloc()
# file must be an .applescript source code file, not a compiled script.
if sys.argv[1:] and sys.argv[1]: # else (no filename), use
default string as script.
os.stat( sys.argv[1] ) # file exists ?
src = NSString.stringWithContentsOfFile_( sys.argv[1] )
if not src : raise IOError( "empty? " + sys.argv[1] )
as.initWithSource_( src )
print as.source().encode( 'UTF' ) # applescript source files may have
unicode chars.
# ( and without encode(), printing
unicode can fail )
out = as.executeAndReturnError_()
print out
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.