Using Mac’s Automator to Make Diffing Easier

Recently I’ve been needing an easy way to paste two versions of a text, and get the differences between the texts, specifically changes within a line (most diff programs only show which lines have changed).  After some searching, DiffMerge came up as one of the best free diff programs that would work on the Mac.  DiffMerge is great in many aspects, however, it lacked the interface to paste in text to diff right off the start.

I set out using Mac’s Automator tool to create an application to prompt the user for two texts, create the temporary files, then pass it into DiffMerge.

Automator is a very easy to use visual scripting tool that you can use to create workflows that can be automated (hence the name).  Also, it comes with all Macs!  As great as Automator seems to be, there are some drawbacks: the actions aren’t too customizable, and the flow of data within the workflow is strictly “output” of one action to the “input” of the next.

I came up with the following workflow:

  1. Get value of a pseudo-variable – random identifier
  2. Set the value of the random identifier into a variable so the same identifier can be referenced later (subsequent steps refer to this value as just the “identifier”)
  3. Ask for base text
  4. Store base text in a temporary file (using the identifier as part of the filename)
  5. Ask for new text
  6. Store new text in a temporary file (using the identifier as part of the filename)
  7. Get value of the identifier
  8. Run a custom shell script to open up diffmerge with the files created in the steps above.  Passing in the identifier as an argument of the shell script allows us to figure out the name of the temporary files.  The shell script also removes the temporary files when DiffMerge is closed.

The result was quite successful.  Here is what DiffMerge looks like after pasting in two SQL dumps into the Automator application.  Notice the temporary filename.

I’ve uploaded the app to do this on my GitHub account.  It’s called “PasteDiff.app”.  You can download them, and open the apps in Automator in order to see precisely the actions used.

Many times, computers programs are born out of necessity to reduce repetitive or menial tasks.  For Mac users, Automator’s a nifty tool that can help with that.

If you have used Automator for anything cool, let me know in the comments!

App Remote – Unleashing the Apple Remote

I’ve been using Sofa Control for my Apple Remote since I bought my Mac in 2009.  I use Sofa Control pretty much every week when I volunteer with the youth ministry at my church.  The Apple Remote by itself only works with certain programs that are designed to handle its input and it lacked support for other programs we were using such as OpenSong, which we use for song lyrics.  So I bought a license for Sofa Control.

Recently Sofa Control’s move to the App Store required all existing customers to repurchase the license.  I didn’t want to shell out another $20 for this small utility (as great as it has been, a total of $40 for this utility is a little pricy, considering the latest OS X Mountain Lion upgrade only cost $20), so I decided to see if I could program one myself.

I liked the feature that the application-specific handles were scripted.  I also liked how it was small and tucked away as a menu bar extra.  I definitely wanted to keep these features in my own version.

Yesterday (Labour Day, a statutory holiday) was the perfect day to work on this project.  I started off looking for some APIs to hook into the Apple Remote events.  Quite quickly, I found an Apple Remote wrapper written by Martin Kahr, the developer who created Sofa Control.  (Actually I lied; I looked for Apple Remote libraries weeks ago to determine the feasibility of the project, but I did have to find them again yesterday).

Then I looked for an easy scripting language to embed to receive the events generated from the Apple Remote.  I decided to go with AppleScript, the Mac OS built-in scripting language for two reasons.  First, AppleScript already has hooks to script actions in various applications.  Second, Cocoa already has classes to handle execution of AppleScript.

With two-thirds of my application already complete, I only needed to write a small delegate to receive events from the Apple Remote, and call the appropriate AppleScript.

About 200 lines later, I had a working prototype.  Honestly, there isn’t really much to show in terms of screenshots…

The source code and other technical stuff can be found on my GitHub account.  The binary can also be downloaded from Github (beware currently there isn’t much help or instruction with the package).

So with that, I conclude yesterday was a productive Labour Day 🙂

Side Project 2: Alarm synchronized with Google Calendar

I actually started on this earlier last year when I got back to school in September.  I was finding myself re-setting my alarm clock every night to a different time (due to classes each morning starting at a different time).  I got quite frustrated myself when I forgot to set the alarm or setting it to the wrong time.

I realized that all my classes were in my Google Calendar, so if I could write an alarm app that could read my Google Calendar and automatically wake me up before that (maybe 1.5-2 hours ahead, since it takes about 1 hour to commute to school).

I started in mid-September and then schoolwork hit me and I never got it to a working state.

Now that I have time (although I don’t really have a reason to set alarms these few months), I finished it off to a working state.  It’s written in Java using Google Calendar libraries to hook it up to the web service.

I’ve uploaded the Java code to my Github account.  The code is quite rough right now, probably has a few bugs.  It’s a command line Java application, as it was meant to work on a headless system.  Eventually I’ll probably add a better readme, better documentation on how to use it, and maybe even a GUI.  This project hasn’t really been a priority for me right now since I don’t have to set any alarms these few months 🙂

Side Project 1: Real Time Bus Map in Vancouver

Since TransLink released their new mobile Next Bus site with real-time GPS updates of bus locations, I’ve been trying to find ways to get the data and rehash it into something that  Metro Vancouver transit enthusiasts (more specifically, enthusiasts who chase buses and monitor the transit system’s operation) will find useful.

There were two main shortcomings of TransLink’s site from the viewpoint of a transit enthusiast:

  1. Can’t search for a specific bus.  Often times transit enthusiasts “chase” a particular bus, usually a new bus, a fresh bus after a midlife refurbishment, or a bus with a new advertisement wrap.
  2. Can’t see the entire system as a whole.  This one’s pretty self explanatory.  It’s just fun to be able to see where all the buses are.

So I created a system which gleaned information from the TransLink site and aggregated it into a useful interface which I called “T-Comm”.

This is named after CMBC’s Transit Communications centre which has an interface similar to what I created.  Using the information I was also able to add additional functionality like grabbing the bus’s schedule for the current trip and even the entire day.

Since most transit enthusiasts would be using this on the go, I knew I had to make this site mobile-friendly. The enthusiasts I knew used a myriad of mobile devices including Blackberries, iPhones, and Androids, so it would not have made sense for me to create a native app for each of the platforms; it would have killed me in terms of time and energy.  I chose to use jQuery Mobile and Google Maps API as the basis of the frontend.  The backend is powered by PHP/MySQL. I was amazed at the ease I was able to make something mobile-friendly using jQuery Mobile.  It was actually fun too.  More importantly testers reported positively on their mobile devices.

I’m hoping that TransLink will release the GPS data officially for developers.  They’ve said after April 2012 on Twitter, so I’m crossing my fingers.

Contact me if you would like access to the site.  Since the current site hammers TransLink’s servers I’m trying to tread lightly.  Once official GPS data is used I will open it to the public, but I don’t really see this being used by the public as it is quite enthusiast-oriented.

Update: The site has been updated to use TransLink’s official data feed for real time bus data, so here’s the link: https://tcomm.bustrainferry.com.  More updated info on this project can be found on my T-Comm project info page.

Exit mobile version