Hey guys,
So I’m building a small Idle Handler that will customize my workspace depending on what season of the year it is. It’s starting out very simple, just changing the desktop image and spitting back a themed quote for the heck of it. Anyways, I had some questions, which I’ll get to, but first some context:
The big picture idea is that every day the idler will check the current date against a series of specific dates I’ve assigned (4 - one for each of the solstices), and if the current date is one of the solstice dates, the desktop will change – and stay changed – until the next solstice.
I’ve tested this on a small scale, where instead of having it compare against dates in the year, I had it compare against minutes in the hour. That seemed to work out just fine. The handler checked what minute it was every minute, and the desktop changed according to the times I assigned and spit back the quote. So far so good.
I wanted to test it on a medium scale (days of the week against current date where “Wednesday” would be Winter, “Thursday” would be Spring, and “Friday” would be Summer). So I set my idle timer to 12 hours, instead of 1 minute (43200 seconds instead of 60). And yet when I looked at my computer this morning, my desktop hadn’t changed and I was missing a quote. This seemed to be where things fell apart, so I had a few questions:
- Can Idle handlers still run – and activate – if a computer is locked? (NOT turned off, just locked)
- Does unlocking a computer that has an idle handler restart the idle handler’s count?
- Below is my code for the final product, not the smaller scale tests: will it work? Why or why not?
Thanks for your help everyone!
PS – the file names are all correct, I double checked that first!
on idle
set WinterSolstice to date ("21/12/2016" as string)
set SpringSolstice to date ("20/3/2017" as string)
set SummerSolstice to date ("21/6/2017" as string)
set FallSolstice to date ("22/9/2017" as string)
set WinterDesk to "Macintosh HD:Users:npeterson:Documents:Desktops:Wild Triangle.jpg"
set SpringDesk to "Macintosh HD:Users:npeterson:Documents:Desktops:Sky Triangle.jpg"
set SummerDesk to "Macintosh HD:Users:npeterson:Documents:Desktops:Yellow Sky Triangle.jpg"
set FallDesk to "Macintosh HD:Users:npeterson:Documents:Desktops:Firewatch.jpg"
if the FallSolstice is the (current date) then
tell application "Finder" to set desktop picture to FallDesk
display dialog "Autumn is a second spring when every leaf is a flower. - Albert Camus" buttons {"How Serene"} default button 1
else if the WinterSolstice is the (current date) then
tell application "Finder" to set desktop picture to WinterDesk
display dialog "The pine stays green in winter...wisdom in hardship - Norman Douglas" buttons {"Smart Advice"} default button 1
else if the SpringSolstice is the (current date) then
tell application "Finder" to set desktop picture to SpringDesk
display dialog "It was one of those March days when the sun shines hot and the wind blows cold: when it is summer in the light, and winter in the shade. - Charles Dickens" buttons {"Every March, amirite?"} default button 1
else if the SummerSolstice is the (current date) then
tell application "Finder" to set desktop picture to SummerDesk
display dialog "Summer bachelors like summer breezes, are never as cool as they pretend to be. - Nora Ephron" buttons {"Dem bois"} default button 1
end if
--this checks the current date against the solstice date every day.
return 86400
end idle
--What I want/To Do List
--Script runs automatically, using a Idle Handler.
--Checks the day every day.
--If it is the day of a new Season (March 20, June 21, Sept 22, Dec 21) then change the desktop image to the pre-defined and seasonally appropriate image and deliver a dialog box when the change is made
--If it is NOT the day of a new Season, don't do anything, just keeping tracking those days, my man!
--Run this check forever.