Southwest flight alarms with sound

Last fall I wrote a script called swicsfix that cleans up the calendar files provided by Southwest Airlines when you make a reservation.

Southwest Calendar Files

The script does three things:

  1. It gets rid of all the marketing cruft that Southwest wants to inject into your calendar.
  2. It rearranges the important information, like your flight and confirmation numbers, to make it easier to find when you look at the event on your computer or your phone.
  3. It sets an alarm for 24 hours and 5 minutes before your flight, so you can go online and check in as soon as possible to get a good spot in line.

The reasoning behind these changes and additions is described in the first post I wrote about swicsfix. The second post describes another small change I had to make (removing some Microsoft-specific components) to prevent the Mac version of Fantastical1 from getting confused.

Recently, I’ve learned of another deficiency in the script. Although the alarm is set correctly, it doesn’t cause an alert sound to play on your Mac. I suppose I didn’t notice this earlier because my iPhone’s alert sound always did play. It was only when I was on my Mac and my phone was in another room that I noticed that the Mac was silent when the notification appeared—despite the “Play sound” checkbox being ticked in the Notifications setting.

Notification Center Settings

The problem is in the .ics files that come from Southwest. Within the VALARM component, there’s an ACTION item that determines what happens when the alarm goes off. Southwest has that item set to DISPLAY instead of AUDIO, and that’s why the Mac is silent.

Why does the iPhone sound an alert even with ACTION set to DISPLAY? Maybe it’s because the iPhone’s Notification settings override the ACTION setting. Or maybe it’s because the iPhone never sees the .ics file itself. I download the .ics file from Southwest on my Mac, and that’s also where I run swicsfix and add the entry to my calendar. The iPhone learns of the new entry when it gets an update through iCloud. Maybe the iCloud-mediated entry is sound-agnostic and lets the iPhone decide what to do.

However the iPhone works, I don’t want my Mac to be silent when the alarm goes off. So I’ve made a small change to swicsfix that sets the ACTION item to AUDIO. Here’s the new version:

 1:  #!/usr/bin/python
 3:  from icalendar import Calendar
 4:  import sys
 5:  from datetime import timedelta
 7:  for ics in sys.argv[1:]:
 8:    # Open the ics file and extract the event and alarm.
 9:    cal = Calendar.from_ical(open(ics).read())
10:    event = cal.walk('vevent')[0]
11:    alarm = event.walk('valarm')[0]
13:    # The last word in the location is the flight number.
14:    # The last word in the summary is the confirmation number.
15:    flight = event['location'].split()[-1]
16:    confirmation = event['summary'].split()[-1]
18:    # Erase the event's verbose description and rewrite its summary.
19:    event['description'] = ''
20:    event['summary'] = 'SW %s (%s)' % (flight, confirmation)
22:    # Get rid of the mistaken MS fields.
23:    try:
24:      del event['x-microsoft-cdo-alldayevent']
25:      del event['x-microsoft-cdo-busystatus']
26:    except KeyError:
27:      pass
29:    # Set the alarm to 24 hours, 5 minutes before the flight and
30:    # rewrite its description.
31:    alarm['trigger'].dt = timedelta(days=-1, minutes=-5)
32:    alarm['description'] = 'Check in SW %s (%s)' % (flight, confirmation)
34:    # Make the alarm audible.
35:    alarm['action'] = 'AUDIO'
36:    # alarm.add('ATTACH;VALUE=URI', 'Basso')
38:    # Write the changes back to the original file.
39:    f = open(ics, 'w')
40:    f.write(cal.to_ical())
41:    f.close()

As before, you’ll need to install the icalendar library to get this script to work; it isn’t included with OS X by default.

The addition is in Lines 34–36. Line 35 is the important one, and it does exactly what you’d expect. Line 36 is optional; it lets you choose which sound plays (on your Mac) when the alarm goes off. I have it commented out because I’m happy with the default sound my Mac makes, but you could uncomment it and replace Basso with any of the alert sounds.

I should mention that swicsfix was originally written and run on Mavericks and this latest version has been tested on Yosemite only. Although I think it’ll run on other versions of OS X, I make no guarantees.

  1. This was the menubar-only version of Fantastical, not the full-fledged application Flexibits sells now. I haven’t upgraded to the new Fantastical, so I don’t know if the deMicrosofting is still necessary. It certainly doesn’t hurt.