Tag Archives: launchctl

Been a little busy…

With my new job, I haven’t had much time to add much to this website.

So here’s this small perl script I wrote that sends a summary of the weather in SMS format from my iPhone daily.
There was a need, so I figured why not help out those who need the weather forecast =].

use LWP::Simple;
use JSON qw( decode_json );
my $lastRun = 0;
open (MYFILE, 'weatherSMS_LastRun');
while (<MYFILE>) {
        $lastRun = $_;
close (MYFILE);
my ($S,$M,$H,$d,$m,$Y) = localtime($lastRun);
my ($S2,$M2,$H2,$d2,$m2,$Y2) = localtime(time);
if ( $Y2 == $Y && $m2 == $m  && $d2 == $d ){
	exit 0;
$json = get("https://api.forecast.io/forecast/APIKEY/LATITUDE,LONGITUDE?units=ca&exclude=currently,minutely,hourly,flags");
my $decoded = decode_json($json);
#ensure we can write the file
open(F,'>weatherSMS_LastRun') || die "Could not open file to mark execution";
print F time;
my @timeslot = @{ $decoded->{'daily'}{'data'} };
my $forcast = "";
foreach my $f ( @timeslot ) {
	my ($S,$M,$H,$d,$m,$Y) = localtime($f->{"time"});
	$m = $m + 1;
	$forcast .= "$m/$d: ".sprintf("%.3f",$f->{"temperatureMin"})."-".sprintf("%.3f",$f->{"temperatureMax"})."C ".$f->{"summary"}."\n";
`/Applications/biteSMS.app/biteSMS -send -carrier PHONENUMBER "$forcast"`;

In order to execute this daily, the following plist was used:

<?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">
		<string>/location to perlscript/weatherSMS.pl</string>

Submit it to be executed hourly by running `launchctl load [path to plist]`

Edits were made to cover the fact that your phone may not always have internet.
(It may be locked/sleeping – which may turn off the wifi?)