This has been a learning experience for me. Everything checks out logically to me in this script/ plist but something isn't correct. Everything runs, but then the script runs every minute which is getting annoying since I'm opening a few programs in the script. If typing code it gets frustrating as it changes the active window.

Note, this is my first applescript and plist excercise so feel free to critique my code. The goal of the script is to be scheduled to run twice daily (2 plists) - in the am change my IM status to available, open some programs and enable an email account. In the evening, change status, disable email.

Since it's re running I figured it was simply the plist, but comparing it to other templates for accomplishing a task which repeats once daily it checks out to me.

So I'm assuming in my ignorace I have something that's not sucessfully closing an if statement or somethign is just done ineffeciently. Here's the script.

set offTime to 17
set onTime to 9
set dayOfWeek to weekday of (current date)
set theHour to get the (hours of (current date))
if theHour ≥ offTime or dayOfWeek = Saturday or dayOfWeek = Sunday then
#LEAVE ME ALONE!!!!
tell application "Mail"
set enabled of account "mailbox" to false
end tell
tell application "Messages"
set status to invisible
end tell
tell application "Microsoft Lync"
quit
end tell
else if theHour ≥ onTime then
#I'm available for contact
tell application "Mail"
set enabled of account "mailbox" to true
end tell
tell application "Messages"
set status to available
end tell
tell application "Microsoft Lync"
activate
end tell
tell application "Firefox"
activate
end tell
tell application "Coda 2"
activate
end tell
tell application "Google Chrome"
activate
end tell
end if

I guess I could do an absolute value say
else if theHour = 8 and theMinute = 2 then

but I'd prefer the way it is now since My computer may be off when this is scheduled to run, and I believe this will run on wake, or maybe it was a helpful sideeffect of the repeating... I can always change the plist to run on startup as well.

Yeah that's something to consider; however, it then requires two separate scripts instead of one. (one run by each plist) That's not a big deal, but I don't feel it's as elegant as a solution. I presently am using 2 plist files created through Lingon 3 which call the same applescript file exported as an application.
–
Ryan HollingsworthMay 9 '13 at 17:53

I'm with the plist aspect of your question, but this script will run and stay open in the background checking the time every four minutes ( customizeable )to see if the day or time necessitates a status change. Does that work in your situation?

Any links to explain your use of plists above would be appreciated.

property idleTImer : 10 --seconds
property toggleAvailable : false
on run
set toggleAvailable to false
say "launching change status script."
end run
on idle
say "checking status."
set offTime to 17
set onTime to 9
set dayOfWeek to weekday of (current date)
set theHour to get the (hours of (current date))
if theHour ≥ offTime or dayOfWeek = Saturday or dayOfWeek = Sunday then
if toggleAvailable then
say "LEAVE ME ALONE!!!!" --or whatever you want to do here
set toggleAvailable to false
else
say "Status is already NOT available. Do nothing."
end if
else
if theHour ≥ onTime then
if not toggleAvailable then
say "I'm available for contact" --or whatever you want to do here
set toggleAvailable to true
else
say "Status is already available. Do nothing."
end if
end if
end if
return idleTImer --idle time is set to whatever positive value the idle handler returns.
end idle

What I've noticed is that any time I used a date reference (say if day is Saturday or hour is past 5) it's ignored or confuses the script when run from a plist, but runs fine when run manually. Someone had suggested allowing the plist to handle all the timing aspects of the action I was trying to do so that's essentially what i did. No links to share other than the code i've already shared. My goal is to unplug myself from work at a certain time because I have a bad habit of accommodating "emergencies" that come in after hours.
–
Ryan HollingsworthMay 17 '13 at 14:24

I could try something like you've suggested and not use plist at all. Set an idler and run the script at startup.
–
Ryan HollingsworthMay 17 '13 at 14:25