Reputation: 2507
I am getting an AppleEvent timed out error when my Applescript is running and the screensaver turns on and locks the screen. The applescript completes the current operation and when trying to do the next Finder operation it does not proceed but waits and times out.
I cannot increase the time-out time limit since I will not unlock the screen at all. Is there a way to ignore waiting for the screen unlock or some other solution to this?
Thanks in advance.
Upvotes: 2
Views: 2142
Reputation: 2507
The best answer I have received (from macscripter.net) is to use shell commands instead of Finder commands to avoid this timeout.
Upvotes: 1
Reputation: 12824
I cannot reproduce your problem. I tried the following script and it worked fine even when the screensaver was running.
delay 10
tell application "Finder"
name of startup disk
end tell
delay 5
tell application "Finder"
contents of startup disk
end tell
The problem must depend on the specific commands your script is executing. What are they?
Upvotes: 0
Reputation: 818
I just did a test using Python + Appscript to do my scripting rather than Applescript and it continued to run without trouble on my system when either the user was suspended (i.e. going to the login window but with the user still logged in) or if the screen save was running. It was a simple script but presumably demonstrates what you needed to do.
Appscript comes with ASTranslate which translates Applescript calls into the equivalent Python + Appscript call. It doesn't handle variables but typically you can do a little cutting and pasting to figure out how to convert your script. It really goes quick and Python is a vastly superior language to script in than Applescript.
#!/usr/bin/python
import sys, os
from appscript import *
import time
def gettodos():
cs = app(u'iCal').calendars.get()
for c in cs:
print c.name()
tds = c.todos()
for t in tds:
print " ", t.summary()
def test():
for i in range(1,1000):
print
print "Run # " + str(i)
print
gettodos()
time.sleep(10)
if __name__ == '__main__':
test()
# change to 0 for success, 1 for (partial) failure
sys.exit(0)
Upvotes: 0
Reputation: 19030
I don't know how you could bypass the locked screen so your code keeps working, however you might use an if statement such that when the screen saver is running then your code isn't executed. That would at least prevent the timeout error. For example suppose you wanted to run a repeat loop 10 times for some reason, and you wanted not to run some code when the screen saver is running... you could do this.
set i to 0
repeat
set screenSaverEngineIsRunning to false
tell application "System Events"
if (exists process "ScreenSaverEngine") then set screenSaverEngineIsRunning to true
end tell
if not screenSaverEngineIsRunning then
set i to i + 1
-- do some code here
end if
delay 1
if i is 10 then exit repeat
end repeat
Upvotes: 0