Category Archives: OSX
Announcing DateRangeParser: Parse strings like “27th-29th June 2010″
In a project recently I was struggling to find a way to parse strings that contain a date range, for example:
- 27th-29th June 2010
- Tuesday 29 May -> Sat 2 June 2012
- From 27th to 29th March 1999
None of the Python modules I investigated (including parsedatetime) seemed to be able to cope with the range of strings that I had to deal with. I investigated patching parsedatetime to allow it to do what I wanted, but I found it very hard to get into the code. So, I thought, why not write my own…
So I did, and I’ve released it under the LGPL and you can install it right now by running:
pip install daterangeparser
Or you can visit the DateRangeParser PyPI page to download it manually, read the documentation, or hack on the code.
The current version will parse a wide range of formats (see the examples in the documentation) and will deal with individual dates as well as date ranges. The API is very simple – just import the parse method and run it, giving the date range string as an argument. For example:
from daterangeparser import parse
print parse("14th-19th Feb 2010")
This will produce an output tuple with two datetime objects in it: the start and end date of the range you gave.
The parser is built using PyParsing – a great Python parsing framework that I have found very easy to get to grips with. It is incredibly powerful, very easy to use, and really shows how limited regular expressions can be! Now that I’ve done this I have an urge to use PyParsing to write parsers for all of the horrible scientific data formats that I have to deal with in my PhD….watch this space!
Essential OS X software #1 – Mail Attachment Reminder Plugin
The first piece of software in my series of essential OS X software is a very handy tool which reminds you when you haven’t attached a file in an email when you intended to. How does it do this? Well, it searches for key words in the email and reminds you if, for example, you use the word attached without attaching a file.
This sort of functionality is already present in a number of other email apps such as GMail and Thunderbird, but isn’t present by default in OS X’s mail application. However, this free tool will add it. Simply download it from http://eaganj.free.fr/code/mail-plugin/ and follow the instructions (just make sure you download the beta version if you’ve got Snow Leopard, or it won’t work!)
Using PyDev with with the Enthought Python Distribution
I have recently discovered PyDev – a Python IDE which runs within Eclipse. Although I’d given up on big all-singing, all-dancing IDEs a few years ago I’m really liking it. The Ctrl-Space completion is very handy, as are the number of refactorings that are available from the menus.
Anyway, I use the Enthought Python Distribution (EPD) on my Mac, as it provides Python with a number of important scientific libraries (NumPy, SciPy, Matplotlib etc) in an easy-to-install package for OS X. It’s really handy – and is free for academic use. The only problem with using EPD is that applications can sometimes get confused between EPD and the Apple-provided version of Python.
It turns out that PyDev is one of those applications. If you follow the PyDev installation instructions, it suggests you click the Auto Config button to configure your Python interpreter. This will not work for EPD! Instead, (after deleting the interpreter you have configured already, if you’ve already configured one), click the New button and then fill in the fields as below:
Interpreter Name: This is just a name to refer to the interpreter by – it can be anything you like. I tend to use EPDPython.
Interpreter Path: You’ll need to find the python executable provided by EPD. This is normally located somewhere like:
/Library/Frameworks/EPD.framework/Versions/6.2/bin/python
The best way to find it is to navigate from /Library down the path, choosing the most sensible folder at each stage. When you get to the Versions folder, make sure you choose the latest version (highest number) folder, and then choose the bin directory and then the python executable. Once this is done, PyDev will automatically find the relevant folders to add to your PYTHONPATH, and everything will be working.
Alfred – the new Quicksilver?
For a while I used Quicksilver, but it seemed to be rather unstable on my machine. Then I used Quick Search Box, but it got terribly slow. Then, somehow, I found out about Alfred - and it’s replaced them both.
Alfred, like the other applications mentioned above, is a launcher, but it does far more than just launch things. Alfred will let you search websites, find local files, define words, perform calculations, email files, find contacts, and is very extensible as it has good command-line integration.
The basic app is free, but you can buy the add-on PowerPack for £12 (that’s around 20$ for those in the states) which gives you access to the advanced features such as terminal integration. So – have a try of the free version, and buy the extension if you like it or need the extra features. Overall I’d thoroughly recommend it. It’s completely replaced the other two for me – and is so much faster that I can’t see how I coped with the slowness of Quick Search Box.
Stay tuned for some more Alfred posts soon – including how I have set up some useful command-line tools to work with it.
An ode to PDFs (and PDFs as a first class filetype)
Ahhh PDFs…., or more formally, Portable Document Format files. I remember the days when I thought that PDFs were only for instruction manuals downloaded from the internet, or electronic copies of things that you don’t want people to be able to alter. Not so – I have recently discovered the joys of PDFs, particularly through my use of Mac OS X. I will explain more below:
1. PDFs are a vector filetype. That means that when there is text in a PDF document it is stored as text, with details of the font, size and location. When there is a line in a PDF document it is stored as a line from one location to another, with details of colour, width etc. This has a number of benefits – principally that PDFs maintain their quality no matter how much you zoom into them. You never get the horrible pixelated look that you can get with raster graphics files (such as JPEG and PNG). For scientific documents this is great – it means I can generate a graph, and then with one file I can produce an A3 sized copy for use in a poster and a 6″ x 4″ copy for inclusion in the paper. Not only that, but the 6″ x 4″ copy actually looks good – it looks professional, clean and high quality. Recently I had to include a PNG graph in a LaTeX document that I was writing – I hated it, all of the lines were blurry, I couldn’t resize it and it generally looked un-professional. Of course, I’m not suggesting you should store your holiday snaps as PDFs – that’s not what they’re designed for – but for diagrams, graphs and other technical drawings they are perfect.
2. PDFs are cross platform. Nearly every system can read PDFs these days. The standard is now open (ISO 32000-1). There are readers for Windows, Linux, OS X, Android, iOS, Palm, BSD, BeOS – you name it, it’ll probably have a PDF reader. Google Chrome even has a built-in reader these days – and many websites have stopped saying “This is a PDF file. If you don’t have a program to view them please download Adobe Reader”.
3. PDFs can be included in LaTeX documents extremely easily. Yes, I know you can include PNG files just as easily, and possibly it’s even easier to use PostScript files (although who doesn’t use PdfTex these days?). As mentioned above, raster files for graphs just look horrible, particularly when included in a LaTeX document in which (as is nearly always the case with LaTeX) all of the rest of the design and typography is near-perfect.
4. PDFs do not have to be A4 sized (or Letter, for those in the US). I know – I didn’t realise this until very recently, but you can crop PDFs to any size. In fact, there is a great perl script called pdfcrop which will crop a PDF file to the minimum bounding rectangle of the contents – taking your A4-sized PDF with a 6″ x 4″ graph in it down to a 6″ x 4″ PDF – perfect for inclusion in a LaTeX document, for example.
5. PDFs can be annotated easily. For example, as the text in a PDF document is stored as text, it can be selected just like text in a word processor, and then highlighted just as easily. Of course you can also add extra text or vector illustrations (such as circles around important features in a diagram). This is great for making notes on, and highlighting papers, articles and e-books.
6. PDFs are a first class filetype in OS X. I never knew how much I’d value this until I started using OS X. By default so many things are PDF. For example, PDF export is built into the standard OS X print dialog box. On Windows you’d have to install something like CutePDF to do that – but OS X does it by default. In fact, if you use the Print Preview function in the print dialog box, OS X simply prints to a PDF and shows you the PDF in the aptly-named Preview application. In fact, this application – which can display almost any graphical filetype – is also a powerful PDF editor. Using Preview you can re-order PDF pages, merge PDFs, annotate PDFs and crop PDFs. PDFs are a first class filetype in other ways too – all Spotlight searching by default searches within text in PDF files, and there is a separate section in the Spotlight dropdown for PDF files. Overall, Apple just seem to ‘get’ PDF.
Amazing software you haven’t heard of
Every so often, on my travels around the internet, I come across a piece of software which is so great that I wonder why on earth I haven’t heard of it before. The software listed below falls into this category, and hopefully by posting the list here I will allow more people to find them.
AeroFS
This is an online file-synchronisation service similar to Dropbox but with one key difference: nothing is stored on a cloud server unless you specify that it should be. That is, the synchronisation takes place through a securely encrypted tunnel between your computers running AeroFS, and is never stored in the cloud. This has a number of benefits: it means you can store as much as you want on your AeroFS drive without having to pay for cloud storage, and it means that data is not stored on third party computers (essential for some business applications). It is cross-platform (Windows, Linux, Mac) and free – what more could you want?
Caffeine
This simple app does one simple thing, but is invaluable. Do you ever find that your MacBook screen’s backlight goes off while you’re busy watching a film, showing your family photos, or busy watching a process complete. By clicking the coffee cup icon that Caffeine puts in your menu bar you can stop the screen backlight from switching off. Simply click the icon again to get it back to normal.
Max
We’ve all done it: suddenly needed to convert an audio file and googled “Convert from X to Y” and found a huge list of ad-riddled pages explaining how to do it if you buy their ghastly shareware software. Although I sometimes like to stick to good-old command-line tools like ffmpeg, I quite like finding a nice GUI tool to do this. Max allows you both to rip CDs (through a variety of methods) and convert audio files that you already have, all through a nice GUI interface, with no dependencies on other software. Unfortunately it’s Mac only.
Evom
Similar to Max, but for video – this program will convert any video files you have to other formats, and download YouTube videos to any format you want. It’ll even let you convert files into just the right format for playing on various hand-held devices (iPods, iPads, mobile phones etc).
DTerm
I’ve mentioned DTerm before on my blog, and I really can’t live without it on my Mac now. It allows you to quickly open a simple command prompt in any directory, and execute a command there (with full output shown), or switch immediately to a terminal focussed on that folder, ready to do any other processing you might need. It does full command-line completion, and I haven’t yet found a command that won’t work in DTerm’s terminal.
My favourite OS X software
I’ve spent the last couple of months getting used to my new MacBook Pro, and I must say that overall I’m really liking it. Continuing my previous posts about my mac, here are my favourite three pieces of OS X software:
Preview
This is the built-in image and PDF viewer that comes with OS X. Not very exciting, you might think, but it is actually a very powerful piece of software. As well as viewing images and PDFs (including lovely smooth scrolling and zooming) it will let you modify them in a variety of useful ways. For example, you can re-order pages in PDFs, combine two (or more) PDFs into one file, and crop PDFs and images. You can also annotate files with highlighting, texting, freehand drawings and any other type of annotation you could think of. Finally, the search feature in PDFs is the best that I’ve ever seen in a PDF reader. Yes, I sound slightly too enthusiastic about this, but I’ve never before found a free, easy-to-use piece of software that has this power when viewing and editing PDF files.
(I can’t provide a download link as it is built-in to OS X)
NetNewsWire
This is a free (ad-supported – you can pay to remove the ads) RSS feed reader for OS X. It’s fast, easy-to-use, and, most importantly, can be controlled entirely with the keyboard. It also displays pretty much everything that is in the original blog post, so if there is a YouTube video inside a blog post then you can play it from within NetNewsWire. This is one of the apps on my list to buy a license for when I have some money…
AirportLocation
This is an unusual app, but it is incredibly useful for those of us who move around a lot with their laptops. For example, as a PhD student I spend time at home, my office at the university, other work rooms at the university (labs and so on) and various other places. Airport Location will work out where you are based on various pieces of information (such as the wireless network you’re connected to, your IP address or your geolocation information) and then change loads of OS X and application settings to make them appropriate for that location. The upshot of this is that when I get to my office my laptop is automatically muted, Skype is set to away, and my default printer is set to the local networked printer, and the opposite happens when I get home.
Git + DTerm = Great Source Control in OS X
Git is my favourite version control system (see Why is Git better than X for some good comparisons with other tools, and my GitHub repositories to see what I’ve been doing with it lately). I now use it for all of my programming projects, and many of my writing projects (as I’m now using LaTeX for nearly all of these).
DTerm is a simple utility for OS X which provides a drop-down Terminal in the Finder. The best way to explain it is with a screenshot (see below). When in any Finder window, press Cmd-Shift-Enter, and the DTerm dialog will pop up. You can type any terminal command in the box, and it will run it in that folder, or you can press Apple-Enter to open a full terminal at this folder and run the command.
The combination of the two gives what is, for me, the best way to do source control in OSX. I simply use DTerm for all (or most of) my git needs. When I realise I need to get some code into source control, a simple git init in DTerm starts a repository, ready for me to do whatever I want with, and then I just commit using git commit -am "Blah" in DTerm. Simple, fast and all the power of the command-line.
(I must state that I do use GitX (a Git GUI for OS X) sometimes, particularly for viewing commit logs and branch diagrams)
How to: Reset the Software Update URL in OS X
Sometimes you may find that your Mac OS X installation has an old URL for the software update service in its preferences, which may mean that you can’t successfully run the Software Update tool under the Apple menu. In my case, I got my Mac from my university and the update server was set to some internal server in their organisation. This server didn’t seem to have the latest updates, and half of the time I couldn’t even connect to it.
From various searches around the internet I found the following process to reset the update server URL to the default:
- Open the /Library/Preferences folder on the main hard drive.
- Find the com.apple.SoftwareUpdate.plist file and move this to the desktop (the easiest way is just to drag and drop the file to the Desktop). If you find a similar file with a .apple at the end (com.apple.SoftwareUpdate.plist.apple) then move that too. Moving them to the desktop means that you can restore them if this goes wrong.

- Run the Software Update tool (Software Update on the Apple menu on the top left of the main menu bar)
- It should all work fine! If not, then you can always restore the files that you put on the desktop (just move them back to /Library/Preferences)
My 3 favourite things about my MacBook Pro
Well, as mentioned before, I’ve recently been given (by my PhD funding body) a MacBook Pro laptop. I’m really getting to like it, but there are still some things that frustrate me. So, this will be one of two posts: my favourite things, followed by my least-favourite things. So, the good bits first:
Instant Sleep/Wakeup
This feature has actually replaced my desire for an iPad! When I close the lid of my MacBook it goes to sleep in about ten seconds and I can put it back in my bag. When I want to use it again, I simply open it up, tap a key, and I’m immediately back exactly where I was. This has really changed how I use my laptop. I’d only get out my Windows laptop when I was sure I’d have a significant amount of time to use it, as it took so long to wake up from sleep/hibernation mode. Now, if I have five minutes to spare I just whip out my laptop and manage to get around four minutes work done! Also, just as an aside, the sleep indicator on the MacBook Pro flashes in a very soothing way…hardly surprising as they deliberately designed it to mimic the human breathing rate during sleep (see here).
POSIX base
I’ve always been a fan of linux (I installed my first Linux distro at the age of around 12), but I’ve never really managed to persuade myself to use it on my main every-day machine. Servers yes, but laptops no – it didn’t have the right software, it was too finicky to do stuff with when I need my laptop to work every day. But now I have a solution – OS X is a very polished desktop operating system, with a linux-y (technically, POSIX-compatible) base. If I want to use GCC on my Mac, it’s there. If I want to install some linux software it’ll often just work. If I want to use a linux-based GUI then an X server is built in to the operating system. And, probably most importantly, there is a decent bash terminal built-in to the operating system. Best of both worlds? Definitely!
Touchpad
I didn’t realise how great this was until I moved back to my Windows laptop for a while. The touchpad on my MacBook is just so smooth and easy to use. Two-fingered scrolling is so easy, as is pinch-to-zoom. I’ve always hated scrolling on touchpads before (they often have a horrible ‘scroll zone’ on the right-hand side) but on my MacBook I use the touchpad to scroll even if I’m plugged into an external mouse!
So, those are my three favourite things. It’s interesting to note that these three things aren’t particularly difficult or complicated things, but they just make my MacBook far nicer to use on a day-to-day basis.
Next time: what frustrates me about my MacBook Pro.


