Prerequisits: iCal, Dropbox. ImageMagick, Applescript, Launchd
Before we get started, I acknowledge that my writing style completely sucks. Please bear with me. This isn't meant to be a step-by-step guide, so I assume you know the basics of the command line interface, AppleScript and basic MacOS stuff. YMMV.
For this to work, you have to have ImageMagick installed. The easiest way to do this is to install MacPorts, and run the command...
sudo port install ImageMagick
I've always used the terminal command "cal" to generate a calendar to display on my desktop with GeekTool. This is pretty boring looking, as you're pretty much limited to monospaced fonts. If you use a regular font, you end up with something like this:
Yuck.
For a few weeks I was taking a screen shot of iCal's mini calendar and using that instead of the cal command. It became tedious as I had to open the screen shot, crop it in Photoshop, etc. I wanted a way to automate the process.
I have a headless Mac that I use as an FTP server and nothing else - it's located in a proper server room and it's on 24/7 - perfect for generating the screen shots. All sleep settings are set to never, as to not bugger up the execution of the scripts.
We're going to be generating three files in all. A full screenshot, screen.png; a cropped down version, today_temp.png; and a composed final version, today.png. These files and the related scripts are located inside of my user library in a folder called ScreenCap.
After the screen shot is generated, it is cropped and composed using ImageMagick, and saved to my Dropbox directory. In my initial testing of the script, Dropbox wasn't properly synching the file for some reason, so I included a command to stop and restart Dropbox.
Step 1: Kill Dropbox dead.
killall Dropbox
Step 2: Remove files generated the previous day.
rm ~/Library/ScreenCap/screen.png ~/Library/ScreenCap/today_temp.png ~/Dropbox/today.png;
Step 3: Execute an Applescript that launches iCal and sets the screen size. [This step was necessary due to iCal's inconsistent screen positioning after launching it.]
osascript ~/Library/ScreenCap/launch.ical.scpt;
launch.ical.scpt contains the following:
tell application "iCal"
activate
tell front window
set bounds to {0, 0, 1280, 1024}
end tell
end tell
Step 4: Capture the screen
screencapture ~/Library/ScreenCap/screen.png;
Step 5: Tell iCal to quit
echo 'tell application "iCal" to quit' | osascript;
Step 6: Use ImageMagick to crop the screen shot.
/opt/local/bin/convert -crop 239x186+0+800 ~/Library/ScreenCap/screen.png ~/Library/ScreenCap/today_temp.png;
Step 7: Use ImageMagick to compose two files together to get rid of the arrows.
/opt/local/bin/convert -composite ~/Library/ScreenCap/today_temp.png ~/Library/ScreenCap/trans.png ~/Dropbox/today.png;
I admit I'm a bit anal when it comes to stuff like this, but I had to do it - it's just too tempting to click on the arrows. Since the upper portion of the calendar is a gradation, I couldn't fill it with a solid color. I made a transparent .png to cover up the arrows and merge them together with the -composite option.
This:
Plus this:
Equals this:
Step 8: Restart Dropbox
echo 'tell application "Dropbox" to activate' | osascript;
Step 9: Create a launchd user agent to execute the script at midnight every night.
Step 10: In GeekTool, use a picture geeklet to place today.png on your desktop.
That's it.
Links
Transparent .png file used for compositing.
My launchd plist file. This goes in ~/Library/LaunchAgents
Screen shot of my desktop:
