on open location emacsURL -- Some paths set emacspath to "/Applications/Aquamacs.app/Contents/MacOS/bin/" set emacsapp to "Aquamacs" set cvspath to "/opt/local/bin/" -- Find file path and BibTeX key positions in URL set p to the offset of "///" in emacsURL set i to the offset of "#" in emacsURL -- File path set fn to text (p + 2) thru (i - 1) of emacsURL -- BibTeX key set bk to text (i + 1) thru -1 of emacsURL set the clipboard to bk -- Line number of BibTeX key (e.g. "grep -n {andersen1998a, A.bib | awk -F:'{ print $1 }'") set ln to (do shell script "grep -n {" & bk & ", " & fn & " | awk -F: '{ print $1 }'") if ln is "" then set ln to "1" end if -- Open file in Emacs on correct line using "+line:ln fn" if application emacsapp is not running then tell application emacsapp to activate delay 2 do shell script emacspath & "emacsclient +" & ln & " " & fn else do shell script emacspath & "emacsclient -c +" & ln & " " & fn end if -- When Emacs window is closed, fetch CVS commit message tell application "EmacsURL" to activate -- Get the dialog frontmost set msg to the text returned of (display dialog "CVS commit " & fn & ":" default answer "Added/modified " & bk) -- If we are on the UiT network, VPN not needed set atUiT to false set ifaces to (do shell script "ifconfig -l -u") set text item delimiters to " " set iface_list to text items of ifaces repeat with iface in iface_list try set ipaddr to (do shell script "ipconfig getifaddr " & iface) if "129.242." is in ipaddr then set atUiT to true end if end try end repeat -- Not at a UiT network: cvs repository needs VPN access outside UIT if not atUiT then -- Are we connected to VPN? try do shell script "ifconfig utun0" on error -- Not connected: we need to connect tell application "Cisco AnyConnect Secure Mobility Client" activate end tell -- Fetch password from keychain set passwd to (do shell script "security find-generic-password -a vpn -w") -- Log in to vpn server tell application "System Events" repeat until (window 1 of process "Cisco AnyConnect Secure Mobility Client" exists) delay 1 end repeat tell process "Cisco AnyConnect Secure Mobility Client" keystroke return end tell repeat until (window 2 of process "Cisco AnyConnect Secure Mobility Client" exists) delay 2 end repeat tell process "Cisco AnyConnect Secure Mobility Client" keystroke (passwd as string) keystroke return end tell end tell end try end if -- Do the CVS check in try do shell script ("cd path/to/bib && /usr/local/bin/bsdmake install && " & cvspath & "cvs com -m \"" & msg & "\"") on error errStr number errNumber display dialog "Warning: \"cvs com\" failed (" & errStr & ")" end try end open location