So, me being a geek and all, I quite naturally wanted to integrate the two and wrote a little AppleScript that asks the user for a bugzilla.mozilla.org bug number, obtains its bug title, and makes a new to-do item for it in Things' Inbox folder.
If you look at the code, you'll notice that I went ahead and embedded some Python code to the script to do the heavy lifting. The problem with AppleScript is not only that it has a hideous syntax, it also completely lacks a standard library for things like downloading websites and regex-parsing strings. Let's look at it a little closer:
set bugtitle to do shell script "echo \"" & bugzilla_url & "\" | /usr/bin/env python -c \" import re import sys import urllib2 bug = urllib2.urlopen(sys.stdin.read()) title = re.search('<title>([^<]+)</title>', bug.read()).group(1) title = title.replace('–', '-') print title \""
set bugtitle to do shellscript ""means, assign whatever this shell expression returns to the variable
bugtitle. This way, we just need to
echo \"" & bugzilla_url & "\" | /usr/bin/env pythonfeeds some input data into the Python script through stdin. We read that a few lines later with
sys.stdin.read(). Another method, especially for more than one input values, would be command-line parameters, all the way at the end of the Python block (after the source code).
- Finally, in
python -c \"mycode\"the
-cmarks an inline code block to be executed by the Python interpreter. Other languages, such as Perl, PHP, or Ruby, have similar operating modes, so you can use those as well.
If you want to install the Things-Bugzilla AppleScript, make sure to download the entire Gist as it also contains an install script for your convenience.