PDA

View Full Version : On Idle Script in Login Items Doesn't Stay Open




astrorider
Nov 12, 2010, 01:39 AM
I have an On Idle Applescript application, saved with stay-open selected, that works perfectly if I open it after I've logged in (i.e. it stays open and does its thing), but seems to return immediately if I put it in my login items. Any idea why this happens or how to troubleshoot what's happening?

Here's the script in case it helps. It sets the mouse off in the corner of my screen if certain apps are running and if PandoraBoy is running it quits it if it remains in a paused state for too long (I launch PandoraBoy from Plex and I need PandoraBoy to quit so Plex will relaunch). Thanks for any help!

property idleTime : 3
global mouseLoc
global counter
global counterMax
set mouseLoc to "maybeBad"
set counter to 0
set counterMax to 3

on idle
tell application "System Events"
set thisApp to name of first process whose frontmost is true

if thisApp is "EyeTV" or thisApp is "Hulu Desktop" or thisApp is "Plex" then
if mouseLoc is "maybeBad" then
do shell script "python -c 'from Quartz import *; CGEventPost(kCGHIDEventTap, CGEventCreateMouseEvent(None, kCGEventMouseMoved, CGPointMake(0,1080), kCGMouseButtonLeft))'"
set mouseLoc to "maybeGood"
end if
else
set mouseLoc to "maybeBad"
end if

if thisApp is "PandoraBoy" then
tell application "PandoraBoy"
activate
if player state is paused then
--say "player not playing"
set counter to (counter + 1)
else
set counter to 0
end if

if counter is counterMax then
set counter to 0
quit
end if
end tell
else
set counter to 0
end if

end tell
return idleTime
end idle