• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: user interaction (& osascript/cron & System Events )
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


References: 
 >'ignoring application responses' stops working ?? (From: Steven Majewski <email@hidden>)
 >user interaction (& osascript/cron & System Events ) [was: 'ignoring application responses' stops working ??] (From: Steven Majewski <email@hidden>)

  • Prev by Date: Re: copy full filepath name
  • Next by Date: Re: quit the dock - possible?
  • Previous by thread: user interaction (& osascript/cron & System Events ) [was: 'ignoring application responses' stops working ??]
  • Next by thread: Solved: Can't make remote AppleEvents work
  • Index(es):
    • Date
    • Thread