Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Takes a bugzilla.mozilla.org bug number from the user and adds a new Things.app ToDo item for it in the Inbox.
#
# Install script for Things-Bugzilla applescript
#
# To install the script into the scripts folder, just run `install.sh`.
#
BASENAME=Things-Bugzilla
AS_FILE=$BASENAME.applescript
SCPT_FILE=$BASENAME.scpt
SCRIPT_DIR=$HOME/Library/Scripts
function install {
osacompile -o $SCPT_FILE $AS_FILE
mkdir -p $SCRIPT_DIR
mv $SCPT_FILE $SCRIPT_DIR/
echo "Script installed."
}
function uninstall {
rm -f $SCRIPT_DIR/$SCPT_FILE
echo "Script uninstalled."
}
function run {
osascript $AS_FILE
}
case $1
in
run)
run
;;
uninstall)
uninstall
;;
install)
install
;;
*)
install
;;
esac
(*
Things-Bugzilla AppleScript:
Takes a bugzilla.mozilla.org bug number from the user, and adds a new
Things.app ToDo item for it in the Inbox.
*)
-- get the bug number from the user
set bugnumber to ""
set clip to (the clipboard as string)
repeat with i in characters of clip
try
set bugnumber to bugnumber & (i as number)
end try
end repeat
set isInputValid to false
repeat until isInputValid
set response to display dialog "Add TODO for the following bug number:" default answer bugnumber
try
set bugnumber to (text returned of response) as number
set isInputValid to true
on error number errorNumber
if (errorNumber = -1700) then
display dialog "No number. Please try again."
end if
end try
end repeat
-- bugzilla URL
set bugzilla_url to "https://bugzilla.mozilla.org/show_bug.cgi?id=" & bugnumber
-- download the bug title
set bugtitle to do shell script "echo \"" & bugzilla_url & "\" | /usr/bin/env python -c \"
import htmlentitydefs
import re
import sys
import urllib2
bug = urllib2.urlopen(sys.stdin.read())
title = re.search('<title>([^<]+)</title>', bug.read()).group(1)
title = re.sub('&([^;]+);', lambda m: unichr(htmlentitydefs.name2codepoint[m.group(1)]), title)
print title.encode('utf-8')
\""
if "invalid" is in bugtitle then
set success to false
else
-- create a new TODO in Things
tell application "Things"
set newToDo to make new to do ¬
with properties {name:bugtitle, tag names:"mozilla, bug", notes:bugzilla_url}
end tell
set success to true
end if
-- register with growl, then notify
tell application "GrowlHelperApp"
set appname to "Things/Bugzilla Helper AppleScript"
set the myNotifications to {"Success Notification"}
register as application ¬
appname all notifications myNotifications ¬
default notifications myNotifications ¬
icon of application "Things"
if success then
notify with name (item 1 of myNotifications) ¬
title ¬
"ToDo successfully added" description bugtitle ¬
application name appname
else
notify with name (item 1 of myNotifications) ¬
title ¬
"Error finding bug" description bugtitle ¬
application name appname
end if
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment