Using AppleScript and iCal to schedule WeatherCat to restart

From WeatherCat Wiki (Mahler)
Jump to: navigation, search

There are a number of reasons for wanting to automatically stop and start WeatherCat. It is recommended that WeatherCat not be run for periods of greater than a week. Another situation when restarting WeatherCat is useful is if you are allowing your computer to go to sleep on a schedule. Because not all weather station interfaces handle the sleep process gracefully, it is recommended that you quit WeatherCat before your computer goes to sleep and restart it after the computer awakens.

One way to do this is using Automator, but creating the Automator actions is a bit tedious. There is a simple trick using AppleScript to use iCal directly and avoid Automator. iCal can run an AppleScript at the time of an event. Since AppleScript can start and stop applications, this is a very easy way to control WeatherCat.

Find your AppleScript Editor (which has different names depending on the version of OS-X you are running.) Open it and give yourself an untitled window if one doesn't immediately appear. Now enter into this window this single line verbatim:

tell application "WeatherCat" to activate

Now save this AppleScript as a script file (AppleScripts default action.) Save this file in some convenient spot on your computer that isn't likely to be disturbed. You could store it in your Applications folder of your home folder for example. Name the file something reasonable like Launch WeatherCat.scpt.

This AppleScript allows you to launch WeatherCat. You'll need a second script to quit WeatherCat. Again get yourself an untitled window in the AppleScript Editor and this time enter the following text verbatim.

tell application "WeatherCat" to quit

Save this as a second file. Again used good judgement as to where to save the file and name it reasonably like Quit WeatherCat.scpt.

Before proceeding any further, test that these applications do what they claim to do. Open each script (double-clicking will work) and then run each script in the AppleScript editor by pressing the "play" arrow. Make sure that WeatherCat launches and quits as intended.

Now open up iCal and create the events to start and stop WeatherCat. If you don't have a "utility calendar" like Automator in the example below, you might want to first create a new calendar only for this sorts of automation tasks. otherwise your appointments will include when WeatherCat starts and stops.

Now create a new event for when you want to start (or stop) WeatherCat. The key is to use Run Script instead of some other alarm as shown in the illustration below:

ICal as Script trigger.jpg

Navigate to where you stored your AppleScripts and select the script for the task you want to perform. Note that the example above actually throws up a Growl notification to remind me to recharge my iPhone (Marvin.) Your script's name will be obvious different. Once you have filled out the remaining fields: iCal will be ready to launch your script as directed.

Repeat this procedure for any additional start-stop events you may need.

As a precaution, it is always a good idea to first test your iCal scripts by having them run at a time when you are at the computer. Once you have shown everything to be working correctly, then change the times to when you want WeatherCat to start-stop while your computer is unattended.

If you prefer not to use your calendar program for this sort of automation, you can use CronniX as described in Using CronniX to schedule WeatherCat to restart.

Personal tools