To know how to code can save you a crazy amount of time when you are a reporter, especially for repetitive tasks.
Some scripts are meant to be used once (to sort a database or to extract data from a pdf file for example). But others are made to run every week, every day or even every hour (like a script that monitors a specific webpage).
Online services, like ScraperWiki, can host and run your scripts on a regular basis.
Note: This tutorial is for Mac users.
For this example, I’ll use a script that my wonderful friend Allie Jaynes (who works for Al Jazeera +) and I coded for fun. This small Python program imitates the Magic 8 Ball, which is supposed to predict the future!
No problem! We’re going to create an executable file that will be opened by Automator, and triggered by the Calendar app!
Let’s start by creating a new text file on the desktop, with TextEdit, with two lines:
- The first line is to tell the computer that it’s a shell file that has to be opened in Terminal.
- The second line is the langage of your script and the path to it.
Now, let’s rename your text file and remove the .txt extension at the end.
Then open Terminal and type the chmod 755 command, followed by the file path.
There we go! You just transformed the file into an executable, that opens in Terminal and runs your script!
It’s a shortcut. Instead of opening Terminal, typing “python”, the path of the script and then pressing Enter, you can now simply double-click on your new file.
Now that this is done, open Automator and choose “Application”.
Drag-and-drop your executable you just created. Add the action to open files. It should look like this:
Save what you did. It will give you an .app file.
All you have to do now is to open Calendar and to create a new event. Modify it so it will repeat itself as many times as you want.
Click on “Alert” and choose “Custom…”, then “Open a file”.
Click on “Others” and select your executable file. Don’t forget to select “At time of event” as well.
Voilà! Your script will run automatically, at the time of your choice!
I am sure there’re other ways to do this. But I really like this method because it’s simple, fast, without too much code and it uses softwares that come with OS X.
Moreover, you can check on your calendar the running time of your scripts. You won’t forget them and can easily manage them as well.
But let me know if there’s an easier way to do so!