Mac & OS X Research Software Sports Uncategorized

GoPro GPS Overlay

Yesterday I decided to get an action camera. The decision between a Garmin Virb and the latest GoPro is probably a topic for another article, so let’s just get the decision out of the way; I ended up getting the GoPro Hero3+ Black Edition. In fact, if I’d decided to get the Garmin Virb this article wouldn’t even be necessary. Why? Read on.

Firstly, I’ll say that there are various reasons for getting an action camera, one of which is the need to record my daily ride to work. Nearly every day I encounter situations that I’d like to have proof of, should the need arise. Read: motorists that probably shouldn’t be on the road in the first place.


So what is this article about? I work in I.T. for a living and like looking at GPS data for my proper rides. So, that means you may or may not find the stuff below a wee bit technical. That all depends what you’re into. Anyway, for the GPS part of things I use a Garmin Edge 800. With an action camera, it makes sense that having some speed or other performance data on screen with the video – it’s the inner geek in me controlling that, no doubt. The Elite version of the Garmin Virb has built-in GPS which makes it very easy to overlay GPS data on top of videos. However, because I bought a GoPro, this is an option I don’t have. Not out of the box, at least. But surely it can be done, right?

The short answer: yes!

Desired result

When I look at a cycling video I’ve made, I want to see the current speed & GPS track at the same time. Not in separate windows, either – on top of the video.

The search

I started out looking online for a way to do what I wanted. I found a few ways, including some software that looked promising. Unfortunately, the software is built for Windows only – I use a Mac. Stumped again!

Fortunately for me I found a blog called Syntax Candy, run by a guy called Bartek – a programmer based in Poland. I found that he’d already written a Java application to do exactly what I wanted – score! There are other apps that will do the same thing, but they aren’t free.

Now, I’ve done a fair amount of development in the past but never in Java. That meant my system wasn’t setup for Java development. The next step? Give my system the ability to compile and run Java applications.

The process

Here’s what I had to do get my system ready to run Bartek’s application. I can only cover what I did on OS X, sorry – YMMV for Windows. Note that ~ refers to your home directory.

  1. Download and install the Java Development Kit. As I write this, version 8 is the current version – click here to download.

  2. Set the JAVA_HOME variable. This step is dependant on your shell – the default on OS X is bash, although I use Zsh. For bash, edit ~/.bashrc and for Zsh edit ~/.zshrc (create the relevant file if it doesn’t exist). Put this line in the file:

    export JAVA_HOME=$(/usr/libexec/java_home)
  3. Download Apache Maven – it is required when running Bartek’s application. Click here to download.

  4. You can put Apache Maven anywhere, but put it somewhere that makes sense as you’ll need to reference that location later. On my system, the full path to Apache Maven is in ~/Applications/apache-maven–3.2.1.

  5. Get the full path to your Apache Maven location. To do this, open a Terminal window and type the following commands. They will return the full path, substituting ~ for the actual path to your home directory. Note that this example assumes your Apache Path is ~/Applications/apache-maven–3.2.1.

    cd ~/Applications/apache-maven-3.2.1
  6. Copy the path that is returned – mine is /Users/chris/Applications/apache-maven–3.2.1.

  7. Add the path from step 6 to your PATH environment variable. This isn’t strictly required, but it means you can run Apache Maven without entering the full path to the binary. For bash, edit ~/.bashrc, for Zsh edit ~/.zshrc. On my system, the PATH declaration is as follows – yours will be different, but you can see where I’ve added the Apache Maven path.

    export PATH="/Users/chris/Applications/apache-maven-3.2.1/bin:/Applications/MAMP/bin/php/php5.4.25/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/MacGPG2/bin"
  8. Download the GpsVideo application from Bartek’s blog. Click here to read and download.

  9. Extract the application’s archive somewhere. It doesn’t matter where, as long as you can access it via the Terminal.

  10. Open a Terminal window and change to the directory you extracted the application to. Type the following command. This might take a while as Apache Maven needs to download a bunch of files that are required to run the application.

    mvn package
  11. In the same Terminal window, type the following command. You must be in the GpsVideo application’s directory for this to work.
    mvn compile exec:exec

Here is what the contents of the Terminal window should look like (yours may look different depending on themes, etc).

GpsVideo - Terminal Output
GpsVideo – Terminal Output

And here is what the app should look like, when running correctly.

GpsVideo - Application
GpsVideo – Application

That’s it! If you’ve done everything correctly, the GpsVideo application should run after a few seconds.

GPX files

The Garmin Edge cycle computers save GPS and tracking data in FIT format (by default). For the GpsVideo application, the data needs to be in GPX format. This means taking the FIT file and converting it using something like Garmin Connect or rubiTrack. rubiTrack isn’t free, but the trial version’s only limitation is the number of activities you can have. Imported activites can be exported as GPX from there or Garmin Connect very easily.

What does it look like?

Here’s a screenshot of what a video produced by GpsVideo looks like – not bad at all!

GpsVideo - Video Sample
GpsVideo – Video Sample
Archived Mac & OS X Uncategorized

Synchronise Coda 2 Configuration with Dropbox

Coda 2

Coda 2, one of my favourite code editors, was released on May 24th 2012 to a somewhat underwhelming reception, in my opinion.  To be 100% honest, I’m a bit disappointed with Coda 2, not for product or feature reasons, but because of the responses it has made some people come up with during their testing and usage of a brand new product.

I’m not going to review Coda 2 myself – plenty of other websites have already done that – but I am going to address one of the questions that seems to have come up a few times, despite Coda 2 still being a relative infant as I write this.

What question?

Synchronisation.  By that I mean the ability to maintain the same settings between multiple Macs running Coda 2.  The first thing I need to make clear is that if you purchase Coda 2 from the Mac App Store, iCloud synchronisation is already built-in but, if you buy Coda 2 directly from Panic, you can’t use iCloud to sychronise your configuration.  Panic’s own FAQ page has this to say about it:

At the moment, there is only one difference between the two versions: the Mac App Store version will support iCloud syncing of Sites and Clips, and the direct version will not. This is a restriction imposed by Apple.

So we’re screwed, right?

Well, no, and if we’re a little bit smart about it, the solution is relatively simple – Dropbox.  Given that OS X stores most application configuration in well-known locations like ~/Library/Application Support and ~/Library/Preferences, synchronising those directories with Dropbox is even easier than on competing operating systems that use things like the *gulp* registry.  By the way, in case you’re not sure, ~ means your home directory …

Others have written articles about how some of Coda’s competitors can be synchronised using Dropbox and this solution is really no different – all I’ve done is automate the process a bit.


By moving the following bits to Dropbox:

  • The Coda 2 main configuration directory
  • The Coda 2 recent files list
  • The Coda 2 user preferences file

No really, how?

If you’re familiar with the term “symbolic link”, you’ll know what’s coming.  If you’re not, you can run the script below and everything will be done for you.  That said, you should be familiar with how to grab a script and, if necessary, make it executable – sorry but this isn’t the right place for me to explain how to do that (hint: chmod +x script_name).  Besides, I’d imagine readers of this article are relatively technical anyway, right?  😉

Anyway, grab the script below, edit the paths at the top if you need to, then run it.  A couple of warnings, though:

  • Before running the script on any Mac, please make sure Coda 2 has been run at least once
  • The first Mac you run this on should be the one where Coda 2 is configured how you’d like it
  • On subsequent Macs, you must make sure you you edit the script and change the first_run variable to FALSE before you run it … if you don’t, the existing Coda 2 configuration in Dropbox will be overwritten

The script will do a few checks while running, move your Coda 2 configuration to Dropbox, delete the local configuration and then create some symbolic links to the new Dropbox versions.  As far as Coda 2 is concerned, nothing has changed – it still operates as if the files are in the same place they’ve always been.

Archived Mac & OS X Uncategorized

Getting Hazel for Mac to process subfolders

Back in February 2011 I wrote an article called Running HandBrakeCLI from Hazel that described how to setup Hazel for Mac to automatically run Handbrake from the command line. The idea of this is to run Handbrake automatically when a video file appears in a specific folder and convert the video to .m4v format suitable for iTunes.

This is a quick update to that post that shows how to setup Hazel to also process subfolders as, up until now, the Hazel configuration I had only processed a single level of folders.

The Hazel Rule

The configuration is pretty easy. Simply add a new rule at the top of your Hazel rules, making 100% sure it is above the rule that runs to automatically convert the video files.

The rule order looks like this:

Hazel rule order

Hazel rule order

The rule itself looks like this:

Hazel rule to process subfolders

Hazel rule to process subfolders

Once that rule is in place and the order is correct, the following rule will run once a new subfolder is found in the appropriate location.

Archived Mac & OS X Uncategorized

Using PuTTY ssh keys on OS X

As part of helping a friend with some system support soon, I was sent a set of ssh keys so that I can access their Ubuntu servers.  The keys, however, are .ppk keys generated by PuTTY, the popular Windows SSH telnet/ssh client.

Unfortunately, the PuTTY keys don’t work for me as I’m using OS X … insert appropriate Mac-hating statement here, if you must.  😉  Needless to say, I had to find a way of using those keys so I could access the servers without any problems.

Fortunately for me, I’ve encountered this situation before.  While testing some connectivity issues recently I kept getting denied access.  The problem is that the keys need to be converted to OpenSSH format before they’ll work with command-line ssh in OS X.

To fix the issue, you’ll need PuTTYGen from the PuTTY website (don’t worry, it’s free).  If you don’t have it already, grab it, and follow the simple steps below (I’ll include the step to download, just in case you missed it).

Note: You’ll need access to a Windows machine for the below steps to work.

  1. Download PuTTYGen from the PuTTY website.
  2. Run PuTTYGen.exe, and open the .ppk file using the open option on the File menu.
  3. From the Conversions menu, export the key in OpenSSH format – it’s what you need for the key to work with OS X.

Once you’ve done all that, you should be able to run ssh from the OS X command line and connect without any problems.

Note: There are a ton of people who have experienced this issue and nearly every other website will tell you that you need to set the permissions on the .ssh file to 700.  In most cases 600 is enough.  If you don’t do this, you can receive an error like this one:

ssh Error
ssh Error

That’s all there is to it – easy.

Archived Mac & OS X Uncategorized

Delicious bookmarks to Evernote using AppleScript

Over the last day or so I’ve been trying to find a decent alternative to Yahoo’s Delicious online bookmarking service.  It’s a service I’ve used for many years (since 2006, in fact) and, unfortunately, Yahoo has sold the service to AVOS.  To be fair, AVOS does plan to keep Delicious running and also implement improvements but with the purchase of an iPhone 4 it makes sense for me to transition to a service that I can synchronise between all my devices.

What is the chosen alternative?

I’ve been a long-time user of Evernote and its ability to sync between Mac (all my hardware), Windows (at work) and iPhone (in my pocket) makes it a sensible choice for the transition.  However, I needed to find a way to transfer all 2628 of my bookmarks to Evernote.

First attempt

My first go was to use the web service from Dr. Palaniraja but that didn’t do some of the things I needed.  For example:

  • It didn’t keep my tags, despite the website saying it would (this effectively made it useless for me)
  • It required a lot of manual input.  I don’t mind this so much but less technical users probably would.

I was looking for an automated way to transfer everything.  My chosen method is an AppleScript that I found online at Veritrope, which I then heavily modified to do more of the things I wanted.

My changes are as follows:

  • The original script verified every URL before adding it to Evernote.  Conceptually this is fine but I wanted to offer the option of not doing that.
  • The original script used the bookmark’s URL as the note title.  To me this is a little odd so I modified it to use the bookmark’s actual title as the note’s title, too.
  • The original script required some manual editing to set your location i.e. Japan, U.S. or outside Japan/U.S. I’m in Australia which meant manually changing the location.  This is easy but I wanted to prompt the user for this information.
  • The original script saved the bookmark’s entire page content as the content of the new note.  This is a great idea but I wanted the option of not doing this, if necessary.  The main reason for this is so that Evernote’s basic account holders don’t blow the cap on their monthly usage.
  • The original script, if verifying URLs, saved all the bad URLs to a single note.  I modified mine to save them as individual notes in a special, local-only, notebook called "Bad Bookmark List".

The script

Here’s the entire script.  All you need to do is:

  • Export your bookmarks from Delicious using their export/download page.
  • Copy/paste the script below into AppleScript Editor (Mac only!) and run it.

The only manual change necessary, if required, is to change the name of the destination notebooks for the good and bad bookmarks.  These two settings are evNotebook and badNotebook respectively.

Warning: Be aware that if you run this script over a big bookmark list and select to verify URLs, it may take a long time to run!

-- v1.30
-- Delicious Bookmark Importer for Evernote
-- February 18, 2011
-- Status, Latest Updates, and Comments Collected at:
-- v2.0
-- June 14th, 2011
-- Chris Rasmussen,
-- Changes:
-- Added prompt for verifying URL
-- Added prompt for saving notes with actual title as title or URL as title
-- Added prompt for location i.e. U.S. or Japan or everywhere else
-- Added prompt for saving the bookmark or full page as the note's content (recommended for Evernote premium users, only)
-- Note : The above prompts would usually be too many but since this script is probably intended to be run once only,
-- more options are better than none
-- v2.1
-- June 14th, 2011
-- Chris Rasmussen,
-- Changes from 2.0:
-- Bad bookmarks are now added to a notebook called 'Bad Bookmark list' (createNote method changed to allow that)

-- *** Make changes in this section, only ***

-- title for dialog prompts
property scriptTitle : "Import Delicious bookmarks into Evernote"
-- set the variable below to the name of the Evernote folder to use for imported bookmarks
property evNotebook : "Delicious Import"

-- note for bad bookmarks - local only (won't be synchronised!)
property badNotebook : "Bad Bookmark List"

-- *** Stop editing here, please :) ***

-- firstly, create the 'bad' notebook
-- we do this now because otherwise AppleScript will, by default, create a synchronised notebook (bad idea if heaps of your bookmarks are invalid)
-- also, an error will be thrown if the notebook already exists - to prevent that, we do a quick check to see if a matching notebook can be found
tell application "Evernote"
	if (not (notebook named badNotebook exists)) then
		create notebook badNotebook with type local only
	end if
end tell

-- prompt the user for their location
global formatDates
property locationOptions : {"U.S.", "Japan", "Outside Japan/U.S."}
set location to (choose from list locationOptions with prompt "Please choose your location:" with title scriptTitle) as string

if location = "U.S." then
	set formatDates to "YES"
else if (location = "Japan") then
	set formatDates to "JP"
	set formatDates to "NO"
end if

-- verify URLs?
-- if the user responds in the affirmative, all URLs will be verified as working before they're added as notes
-- if the users responds in the negative, URLs are not verified and will be added even if they don't work
global verify
property verifyOptions : {"Yes - Verify all URLs", "No - Just import everything"}
set verifyResult to (choose from list verifyOptions with prompt "Verify URLs before import?" with title scriptTitle) as string

if verifyResult = "Yes - Verify all URLs" then
	set verify to true
	set verify to false
end if

-- use bookmark title or URL as new note's title?
-- the original script added notes with the bookmark's URL as the note title
-- this will allow the user to keep this option, if they like, or have the notes' title as the bookmark title (better, in my opinion)
global titleType
property titleOptions : {"Use bookmark's URL", "Use bookmark's title"}
set titleResult to (choose from list titleOptions with prompt "Use bookmark URL or title as note title?" with title scriptTitle) as string

if titleResult = "Use bookmark's URL" then
	set titleType to "url"
	set titleType to "title"
end if

-- save the page's full content as the note's content?
-- if the user responds in the affirmative, the page's entire content will be scraped and saved as the note's body
-- this is recommended for Evernote premium users, only
global contentType
property pageOptions : {"Yes - Save full page", "No - Save summary only"}
set pageResult to (choose from list pageOptions with prompt "Save full page as note's content?  This is recommended for Evernote premium users or small bookmark lists, only" with title scriptTitle) as string

if pageResult = "Yes - Save full page" then
	set contentType to "full"
	set contentType to "summary"
end if

property linkList : {}
property theTags : {}
property linkExists : ""
property badList : {}

-- Main program begins

-- reset items
set AppleScript's text item delimiters to ""
set linkList to {}
set badList to {}

-- select the Delicious export file
set deliciousFile to (choose file with prompt "Choose Delicious Bookmark Export File")

-- open the Delicious export file
set deliciousData to read deliciousFile
set deliciousBody to my extractBetween(deliciousData, "<dl>", "</dl>")

-- get a list of all the links
set delDelimiter to "<dt>"
set deliciousRAW to read deliciousFile using delimiter delDelimiter
my processLinks(deliciousRAW, linkList)

-- process each link into a seperate webclipped note in Evernote, keeping tags and dates intact
my evernoteImport(linkList, theTags)

-- add bad links to a note containing all the bad URLs
if badList is not {} then

	set old_delim to AppleScript's text item delimiters
	set AppleScript's text item delimiters to return
	set badList to badList as text
	set AppleScript's text item delimiters to old_delim
	set badLinks to "List of URLs Returning Errors: " &amp; return &amp; (current date) &amp; return &amp; return &amp; badList as Unicode text

	tell application "Evernote"
		create note with text badLinks title "List of URLs Returning Errors" notebook evNotebook
	end tell
end if

-- child methods

-- get the anchor href info
on processLinks(deliciousRAW, linkList)
	repeat with i from 1 to (length of deliciousRAW)
		set theItem to item i of deliciousRAW
		if theItem contains "A HREF" then
			set end of linkList to theItem
		end if
	end repeat
end processLinks

-- process each link
on evernoteImport(linkList, theTags)
	repeat with i from 1 to (length of linkList)
		set theItem to item i of linkList
		set theURL to my extractBetween(theItem, "A HREF="", """)
		set linkExists to "true" as boolean
		set epochseconds to my extractBetween(theItem, "ADD_DATE="", """)
		set deliciousTags to my extractBetween(theItem, "TAGS="", """)
		set itemTitle to my extractBetween(theItem, "">", "</A>")
		-- change the delimiters to parse tags
		set oldDelims to AppleScript's text item delimiters
		set AppleScript's text item delimiters to ","
		set theTags to text items of deliciousTags as list
		-- change the delimiters back to what they were before
		set AppleScript's text item delimiters to oldDelims

		-- if the user selected to verify all URLs, the URL will be verified here
		if verify then
			my verify_Link(theURL)
			set linkExists to true
		end if

		if linkExists is not false then
			-- add the bookmark to the good list
			if titleType = "title" then
				my createNote(itemTitle, theURL, theTags, epochseconds, evNotebook)
				my createNote(theURL, theURL, theTags, epochseconds, evNotebook)
			end if
			set theTags to {}
			-- add the bookmark to the bad list
			if titleType = "title" then
				my createNote(itemTitle, theURL, theTags, epochseconds, badNotebook)
				my createNote(theURL, theURL, theTags, epochseconds, badNotebook)
			end if
			set theTags to {}
		end if

		if verify then
			-- delay is only required if we're verifying all links
			delay 3
		end if

	end repeat
end evernoteImport

-- verify working URL, if required
on verify_Link(theURL)
		set the_page to do shell script "curl -siL "" &amp; theURL &amp; """
		set the_code to items 10 thru 12 of the_page as string
		if the_code is greater than 400 then
			set linkExists to "false" as boolean
			copy theURL to the end of badList
		end if
	end try
end verify_Link

-- create the note
on createNote(itemTitle, theURL, theTags, epochseconds, notebookName)
	tell application "Evernote"
			set createDate to my epoch2datetime(epochseconds)
			-- create the note based on user's choice of summary or entire page content
			if contentType = "full" then
				-- save entire page (this is the original script)
				set n to create note from url theURL created createDate notebook notebookName tags theTags
				set source URL of n to theURL
				-- save summary only (new option, good for Evernote basic account holders)
				set n to create note title itemTitle with text theURL created createDate tags theTags notebook notebookName
				set source URL of n to theURL
			end if
		end try
	end tell
end createNote

-- convert UNIX epoch time
on epoch2datetime(epochseconds)
	-- adapted from script found at Erik's Lab (
	set myshell1 to "date -r "
	if formatDates is "YES" then
		-- formatted for U.S.
		set myshell2 to " "+%m/%d/%Y %l:%M %p"" -- Formatted for U.S.
	else if formatDates is "JP" then
		-- formatted for Japan
		set myshell2 to " "+%Y/%m/%d %l:%M %p""
		-- formatted for everyone outside Japan/U.S.
		set myshell2 to " "+%d/%m/%Y %l:%M %p""
	end if
	set theDatetime to do shell script (myshell1 &amp; epochseconds &amp; myshell2)
	return date theDatetime
end epoch2datetime

-- extract text between specified delimiters
on extractBetween(SearchText, startText, endText)
	set tid to AppleScript's text item delimiters
	set AppleScript's text item delimiters to startText
	set endItems to text of text item -1 of SearchText
	set AppleScript's text item delimiters to endText
	set beginningToEnd to text of text item 1 of endItems
	set AppleScript's text item delimiters to tid
	return beginningToEnd
end extractBetween

Thanks to Justin from Veritrope for the original idea.

Archived Mac & OS X Uncategorized

Pimp My Desktop using GeekTool

Continuing with the theme of pimping various aspects of the OS X system configuration, today’s article covers how to use GeekTool 3 to display useful info on your OS X desktop.  For those that missed it, one of my recent articles, "Pimp My Prompt … like Paul Irish covered using the .bash_profile script to add some geek bling to your bash prompt – check it out.

The idea of GeekTool is to use the often under-utilised desktop area of OS X to display useful info.  Some people use it to display images but most use it to run Bash shell commands to interrogate and display various system-level statistics.  For example, my desktop looks like this (click for larger version):

My GeekTool Desktop
My GeekTool Desktop

Before you ask, the desktop background is an InterfaceLift image called The Solutionist.  🙂

Now, I’m going to assume that you’ve already downloaded and installed GeekTool 3 from the GeekTool homepage.  If you haven’t done that already, do it now, please.

Once you’ve got it installed, open System Preferences and click the GeekTool preference pane that should now be available.  For this article, please drag a "Shell" Geeklet onto your desktop.  Configure it any way you’d like in terms of position – for the sake of comparison, the screenshot below shows the settings for my date and weather Geeklet.

Date and weather Geeklet settings
Date and weather Geeklet settings
Archived Linux Mac & OS X Uncategorized

A couple more BASH prompt examples

Yesterday I published an article called "Pimp My Prompt … like Paul Irish" in which I showed how to make your BASH prompt similar to the one used by Paul Irish.

I also included a couple of sample prompts that you could use for reference so I figured I’d write a follow-up article that shows what they look like.  So, without any further ado, here they are.

Example 1 – Green username, blue host, magenta working directory, white git branch:

PS1='${GREEN}u${BLACK}@${CYAN}h:${MAGENTA}w${WHITE}`__git_ps1 " (%s)"`$ ‘

The example above uses the short colour codes outlined in the original article and looks like the screenshot below.

Green username, blue host, magenta working directory
Green username, blue host, magenta working directory

Example 2 – Blue user and host, magenta working directory, white git branch:

PS1='[33[0;36m]u@h[33[01m]:[33[0;35m]w[33[00m][33[1;30m][33[0;37m]`__git_ps1 " (%s)"`[33[00m][33[0;37m]$ '

The example above uses the built-in colour codes but can be harder to read.  It looks like the screenshot below.

Blue user and host, magenta working directory, white git branch
Blue user and host, magenta working directory, white git branch

Don’t forget to read the original article, "Pimp My Prompt … like Paul Irish", if you’re unsure about how to enable the __git_ps1 and short colour code commands.

Archived Linux Mac & OS X Uncategorized

Pimp My Prompt … like Paul Irish

There’s been a lot of talk lately about those cool colours that Paul Irish uses in his videos.  If you don’t know who Paul Irish is and you dabble in a bit of web design … well … shame on you!  😉  The things referenced in this article, including the prompt, can be found in Paul’s YouTube video entitled "The Build Script of HTML5 Boilerplate: An Introduction".  Anyway, I think the prompt colours are pretty useful, especially if you’re speedy at navigating your way around the CLI/shell in Linux or OS X and want to see where you are very quickly..  They help identify where you are in the file system, whether or not your current working directory is a git branch and, depending on what options you set, whether or not there are untracked files present etc.

Here’s what Paul’s prompt looks like (screenshot from the video linked above).

Paul Irish’s OS X prompt
Paul Irish’s OS X prompt

I believe Paul is using iTerm, as am I.  Combined with the stuff below, my iTerm configuration looks like this:

iTerm Configuration
iTerm Configuration

Pimp my prompt!

Ok, so you want your prompt to look like that?  It’s not that hard, actually.  You have to grant me a little latitude, though, as I’m guessing what Paul uses the various CLI prefix symbols for.  In this example I’m using an "o" to indicate a working outside a git branch and a + to indicate that the current working directory is a git branch.

This only works if you’re running an OS X or Linux shell – I’m sure you can do it with Windows but I’m not going to cover that here.

Step 1

If you haven’t got one already, open or create a file called .bash_profile in your home (~) folder.  You might be asking why not use .bashrc?  We want the command we’re adding to apply to interactive login shells – .bashrc only applies to interactive non-login shells.  There is an exception to this if you’re using OS X (like me) – .bash_profile is run for each new window, by default.

If a file with that name already exists, make sure you don’t remove anything from it that you want to keep.  From here I’m going to explain what each part of my .bash_profile does.  The complete file will be shown at the end, including a couple of extra bits.

Note: If you’re going to include the git parts, you’ll need to download the git source and put the file .git-completion somewhere (mine is in my home directory).

Archived Mac & OS X Uncategorized

Scheduling AppleScript using iCal

A few days ago I published an article that made my AppleScript backup ‘system’ available for download.  One of the things missing from that article was how to schedule the script so it runs backups automatically – I’m going to address that today.

There are a ton of ways to accomplish the scheduling a script to run.  If you’re hardcore you can use Cron (I won’t cover that here), you can purchase some scheduling software for OS X or you can do what I do – use iCal.

But iCal is a calendar … isn’t it?

Yes, it is.  However, because it’s a calendar, you can add events and set reminders for them.  See where I’m going with this?  Correct – you can run an AppleScript as part of an iCal event’s alarm.  If you read the article about my AppleScript backups, you’ll remember that I said that the idea was to do things with built-in apps, if possible.  Every OS X installation includes iCal by default so it just makes sense to use it here.

Won’t my calendar get messy?

iCal allows you to setup separate calendars for different types of events so no, it won’t get messy if you don’t want it to.  For example, I have a calendar called ‘Backups’ and it holds … wait for it … backups.  🙂  My backup script runs each day at 8:00 p.m. without me having to do anything manually.

Here’s an example of what one of my backup events looks like.  Note that the event is set to happen 15 minutes after the actual backup starts, with the reminder event triggering 15 minutes before that, i.e. at the actual time the backup is to start.

iCal event to run the backup script
iCal event to run the backup script

It really is that simple.  You don’t need anything other than what comes with your OS X installation to do any of this either – that makes it completely free.

If you end up using any of this, I’d love to hear about it.  Thanks for reading!

Archived Mac & OS X Uncategorized

AppleScript ‘Backup System’


Because I’m in I.T. I’m quite paranoid about my data and its safety.  This is partly due to being responsible for the data for companies that would seriously lose hundreds of millions in capital without that data and partly due to losing all my own data many years ago.  At the time I was working on a website editor that, after some semi-public testing, I had been informed was better than the best commercial website editor at the time.  I lost the code, all the files that related to the project and all my backups … my backup software had a bug that killed my ability to restore from tape.  Sigh.

So anyway, I’ve used many methods of backing up my data but I’m overly paranoid about backup software not doing what I want when I *really* want it to and I therefore do my own backups, ‘on the side’, so to speak.


I’m a big fan of doing things as simply as possible and in this case the simplest solution is to take the data I want to backup, archive it in a widely-used format (ZIP) and put it somewhere I can easily get it back.  Naturally this means offsite, outside my house, and in today’s world that means in ‘the cloud’.  Dropbox, in this case.

Now, if you’ve used Dropbox and have given it a bit of a thrashing, you’ll know that as soon as you throw a LOT of files at it, the indexing process really starts to take over, chewing CPU and disk I/O cycles.  For that reason, my solution involving archiving the data into a ZIP file before giving it to Dropbox works nicely.

No, really, how?

My current hardware platform is Mac.  For that reason I figured the best way to back things up without installing anything extra was to write an AppleScript to handle things.  You might argue that I should’ve written it using standard Unix .sh or Bash script so that I could use it on Linux but that’s not a requirement.  Plus, although I wrote this primarily for my own use, I had always planned on making this script publicly available and AppleScript is very easy to understand, even if you’re not a tech-head, like me.  Don’t expect a production-quality script as I’m not trying to sell it so please be aware that there are no warranties provided with anything you download from here.

Is it configurable?

A lot of the settings are, yes.  However, this is a backup script and I therefore chose to keep a number of things ‘set in concrete’, if that makes any sense.  However, being an editable script means that you can just change stuff, if you want.  Here’s what you can change.

  • Prompt on overwrite, if a destination archive already exists
  • The ‘base’ path of your backup destination, by default Dropbox
  • The list of paths that need backing up

In my opinion, you don’t really need to change much more than that.  🙂