But why run and update Xplanet manually, when you can automate.
Property Lists to Launch on Boot and Update (plist)
One of the major changes Apple has made in OS X, and is starting to enforce more stringently, is the use of launchd instead of cron. Both these utilities act as a time-based job schedulers to run commands or shell scripts. While cron is an order of magnitude easier to define and use, it does have limitations that launchd resolves. While you can probably still use cron on OS X 10.8, Apple has officially deprecated its functionality.
I’m making my plist archive available as part of the broader archive available in the Summary. Go to ~/.xplanet/personal/scripts/plist. Change each plist file’s WorkingDirectory string setting within the “[” and “]” to match your Xplanet home directory. Seven plist files, so seven changes. I try to keep the plist as simple as I can which for me means defining the WorkingDirectory and then defining the ProgramArguments and both Standard Paths using “./” or “../“. The benefit of this is that you only have to hardcode the directory one time in the plist and not four, five, or six times. This also means you cannot use the Program key and can only use ProgramArguments.
I’ll walk through an example of a plist below. In this case, it’s the plist to update the quake marker.
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict>
The plist header.
The label should be the name of the plist – minus the “.plist” extension – file. These must match.
Define the working directory the script should run in. You will need to change the [username] in each plist file (seven of them). We unfortunately cannot reference $USER in plist files to make it automatic.
<key>ProgramArguments</key> <array> <string>../xplanet.sh</string> <string>quake</string> </array>
Tell the plist which script to execute and what, if any, arguments to pass to it. I using the ProgramArguments key instead of a combination of the Program and ProgramArguments keys because the working directory is in a different location that the script and the Program key doesn’t support traversing the file system with “..”.
This tells OS X to run, not upon login, but at specified time periods.
<array> <dict> <key>Minute</key> <integer>10</integer> </dict> <dict> <key>Minute</key> <integer>30</integer> </dict> <dict> <key>Minute</key> <integer>50</integer> </dict> </array>
This tells the script to run the 10th, 30th, and 50th minute of every hour. You can also combine, for example, hour and minute times. One key would define the hour to run and another would define the minute during that hour to run, i.e., 10:11 am. You can see this in some of the plists in the archive I made available.
<key>StandardOutPath</key> <string>../../../logs/xplanet.log</string> <key>StandardErrorPath</key> <string>../../../logs/xplanet-quake.log</string>
One of Apple’s launchd most powerful offerings is the ability to define specific files to capture the output of the terminal commands. Here we define the files for the standard out path and, in our case anyway, the misnamed standard error path. Why is it misnamed? Well, the echo commands in the scripts get sent to the standard out path. However, the output when we use curl to download maps and markers, gets sent to the standard error path whether or not the download is a success or failure.
These tags mark the end of the plist.
Copy the seven plist files, after you’ve made the necessary changes in each one, so that OS X can pick them up the next time you log into your Mac. The seven plist files:
- Start Xplanet automatically upon login
- Update the Earth Map at the first of the month
- Update the Cloud Map at pre-defined times
- Update the Earthquake Marker at pre-defined times
- Update the Storm Marker at pre-defined times
- Update the Volcano Marker at pre-defined times
- Update the Label Marker at pre-defined times
cp ~/.xplanet/personal/scripts/plist/* ~/Library/LaunchAgents/
You can load and unload the plist files as necessary using the below commands, e.g., “launchctl load -w local.xplanet.start.plist && launchctl start local.xplanet.start“.
launchctl load -w [location of plist].plist launchctl start [location of plist] launchctl stop [location of plist] launchctl unload -w [location of plist].plist
Or you can log out and then log back in.
Either way, once OS X picks up the plist, Xplanet should display as your desktop background. If it doesn’t, go back and check the links and try everything manually. If it works manually, then the environment isn’t getting set correctly when you try to automate the steps.