WeatherSnoop

Product Support & Discussion Forums 

  • Speak Weather Conditions at Specific Times

  • A forum to share scripting solutions which enhance the usability of WeatherSnoop. AppleScript and other scripting languages are applicable topics of discussion here.
A forum to share scripting solutions which enhance the usability of WeatherSnoop. AppleScript and other scripting languages are applicable topics of discussion here.
 #3209  by boisy
 Mon Jul 04, 2016 8:45 am
WeatherSnoop 3's Weather Reporter provides a concise, human-friendly weather report which can be read aloud by your Mac at chosen intervals (every minute or every hour, for example). However, there may be times where you only want your Mac to read the weather aloud at specific times of the day (for instance, only in the afternoon when someone is home, or anytime but at night when everyone is asleep!).

Although that level of granularity cannot be specified with WeatherSnoop 3 itself, it is possible to accomplish this with some AppleScript magic and a little Terminal foo. To setup your Mac to read the weather report aloud exactly when you want it, follow these steps:

Step 1: Write the AppleScript
Launch the Script Editor. It is found in the Utilities folder under the Applications folder. Create a new document and type in the following code into a file, then save it in your home directory in a file called "say". The Script Editor will automatically add the ".scpt" extension to the file, even though it might not be visible from the Finder.

Code: Select alltell application "WeatherSnoop 3"
   tell agent of first document
      set report to current conditions
      say report
   end tell
end tell


Note that this code assumes you only have one Site Document. If you are using more than one weather station or weather source in WeatherSnoop 3 and have multiple Site Documents open, you will want to specify the site document by name.

Step 2: Setup a cron job
Let's assume you want your Mac to speak the weather report at the top of the hour, starting at 8AM and ending at 1PM. All you need to do is specify these hours in something called a crontab file.

A crontab file is parsed by a utility called cron. Cron is the tool in OS X which runs commands at certain times. In order to setup the crontab file, you will need to type some commands in the Terminal, which can be found in the Utilities folder under the Applications folder.

Launch the Terminal, then type the following command at the prompt:

Code: Select allcrontab -e


You will be placed within the VIM editor and are ready to edit the crontab file. Type the letter 'i', and then the following line:

Code: Select all0 8,9,10,11,12,13 * * * /usr/bin/osascript ~/say.scpt


  • The first field in the line is the minute to run the command. It's set at 0, so this means the action will run at the top of the hour.
  • The second field is the hour to run the action. Here, you are specifying that hours 8-13 (corresponding to 8AM to 1PM) are the hours to run the action
  • The third field is the day of the month to run the action. An asterisk here means that ANY day is fine. The fourth and fifth fields are the month and year, respectively.
  • The sixth field is the command to execute, in this case, the path to the osascript utility. This utility runs AppleScripts.

Once you have typed the line into the crontab file, press the ESC key, then hold down the Shift key on your Mac keyboard and type the Z key twice. This action will save the text you typed and return you to the prompt.

Step 3: Enjoy!
With your script saved and the crontab setup, you should start hearing the weather report at the top of the hour from 8AM to 1PM. Of course, you can edit the crontab file to your liking to change the hours or any other qualifier. If you are the adventurous type, you can learn how to use the VIM editor and its commands at http://www.vim.org.

However, if you want to merely delete the crontab and start over from Step 2, just type the following command at the Terminal prompt:

Code: Select allcrontab -r


This removes the crontab file and the speaking will stop.