Updated December 13, 2016

Here are some scripts I find useful. Most are generic Bash scripts, but a few are AppleScripts or call OS X programs such as Eudora or BBEdit.

In many cases, you'll need to make a few simple customizations on them, as explained below.

I install Bash scripts and command-line utilities in /usr/local/bin/. You can install wherever you like, but some scripts call others, so if you choose a different location you'll need to change the calling script. Also, I find it helpful to add the installation directory to my path, using the shell customization script ~/.bash_profile. For example, to add /usr/local/bin/, add the following lines to your .bash_profile file:

echo $PATH | grep -q -s "/usr/local/bin"
if [ $? -eq 1 ] ; then
    PATH=$PATH:/usr/local/bin
    export PATH
fi

Script Description Dependencies Customization
cwdiff.scpt A BBEdit script (install into ~/Library/Application Support/BBEdit) that runs OS X's excellent diff utility (part of the Developer Tools) or CodeWarrior's diff tool to show differences between an open document and an earlier version of that document. For Internet Drafts, which follow a naming convention where the last component of the name (before the .txt extension) is a version identifier, it runs a small Perl script to guess at the earlier file. For other files, it asks you to pick the file to compare against. In all cases you get to pick a different file, such as if you want to compare version 08 against version 06. Personally, I love BBEdit, but prefer OS X's diff tool, which has a very nice UI, and shows the specific words on a line that are different. Uses cwdiff and get_prev_id. May need to change location of dependencies if they are installed somewhere other than /usr/local/bin/.
get_prev_id Guesses at the name of the previous version of a file (none) (none)
cwdiff Command-line tool to run a diff tool to compare two files. The older file can be specified or it guesses based on the older file. Runs OS X's excellent FileMerge diff utility (part of the Developer Tools), CodeWarrior, or Perforce p4merge. Uses get_prev_id. May need to change location of dependencies if they are installed somewhere other than /usr/local/bin/.
open_id Opens an Internet Draft in your preferred editor. You only need to specify part of the file name; the script finds matching drafts and chooses the latest matching file. If it can't find any matches it uses get_id to download it. It optionally runs get_id in the background anyway to look for updates; if any are found it opens them. Uses get_id if no matching drafts are found or if requested. You may need to edit the directory where you keep Internet Drafts. The default is IETF/Internet_Drafts in your home directory. If you need to edit this, look for the string ID_DIR.

Uses $EDITOR_WAIT if defined, otherwise $EDITOR. If you use BBEdit and set $EDITOR to bbedit_wrap or bbedit -w, define a new environment variable EDITOR_NOWAIT and set it to just bbedit.

May need to change location of dependencies if they are installed somewhere other than /usr/local/bin/.

get_id Fetches Internet Drafts which match a string. On MacOS, optionally sets the file type and creator of downloaded files to open using your preferred editor. Only downloads actual drafts; ignores stubs for expired or published documents. Only downloads files which don't already exist locally. Optionally sends email to let you know when new files have been downloaded, which is handy if you want to run it automatically, such as using cron or launchctl. Optionally runs Eudora or another mail program You may need to edit the directory where you keep Internet Drafts. The default is IETF/Internet_Drafts in your home directory. If you need to edit this, look for the string ID_DIR.

If you want it to send you mail and you don't use Eudora, you'll need to edit the mail program.

If you want to change the creator code optionally assigned on MacOS, look for EDITOR_CREATOR_CODE (default is R*ch).

list_id Lists IDs that you have. You only need to specify part of the file name; the script finds matching drafts and chooses the latest matching file. It optionally runs get_id in the background anyway to look for updates; if any are found it opens them. Uses get_id if no matching drafts are found or if requested. You may need to edit the directory where you keep Internet Drafts. The default is IETF/Internet_Drafts in your home directory. If you need to edit this, look for the string ID_DIR.

Uses $EDITOR_WAIT if defined, otherwise $EDITOR. If you use BBEdit and set $EDITOR to bbedit_wrap or bbedit -w, define a new environment variable EDITOR_NOWAIT and set it to just bbedit.

May need to change location of dependencies if they are installed somewhere other than /usr/local/bin/.

get_rfc Fetches one or more RFCs, the text RFC index, or the XML RFC citation library. On MacOS, optionally sets the file type and creator of downloaded RFCs to open using your preferred editor. (none) You may need to edit the directory where you keep RFCs. The default is IETF/RFCs in your home directory. If you need to edit this, look for the string RFC_DIR.

May need to edit the directory where your xml bibliography files live. The default is individual subdirectories under IETF/bibxml in your home directory. For example, the RFC bibliography files would be in IETF/bibxml/rfc. If you need to change this, look for BIBLIO_DIR.

If you want to change the creator code optionally assigned on MacOS, look for EDITOR_CREATOR_CODE (default is R*ch).

open_rfc Opens an RFC in your preferred editor. If the RFC doesn't exist locally, runs get_rfc to fetch it. Uses get_rfc You may need to edit the directory where you keep RFCs. The default is IETF/RFCs in your home directory. If you need to edit this, look for the string RFC_DIR.

Uses $EDITOR_WAIT if defined, otherwise $EDITOR. If you use BBEdit and set $EDITOR to bbedit_wrap or bbedit -w, define a new environment variable EDITOR_NOWAIT and set it to just bbedit.

May need to change location of dependencies if they are installed somewhere other than /usr/local/bin/.

get_id.plist Put this in your ~/Library/LaunchAgents/ folder if you want to use OS X's LaunchDaemon to automatically run get_id. Edit this file to select which Internet Drafts to look for (such as by group name or area of interest) and how often to run. Runs get_id. Edit this file to select which Internet Drafts to look for (such as by group name or area of interest) and how often to run.
get_rfc_index.plist Put this in your ~/Library/LaunchAgents/ folder if you want to use OS X's LaunchDaemon to automatically run get_rfc at intervals to fetch the latest RFC index file. Edit this file to select how often to run. Runs get_rfc. Edit this file to select how often to run.
RetroClient Replace the file /Library/StartupItems/RetroClient/RetroClient with this file. It does the same thing (launch Retrospect daemon) but better, since it maintains a pid file, and allows the daemon to be stopped and restarted. Called by update_retrospect_config. None needed.
grep_id Searches IDs that you have. You specify part of the file name and a pattern to search for; the script finds drafts with matching drafts and searches the latest matching file for the pattern. It optionally opens those where the pattern is found. Uses list_id and optionally open_id if requested. You may need to edit the directory where you keep Internet Drafts. The default is IETF/Internet_Drafts in your home directory. If you need to edit this, look for the string ID_DIR.

May need to change location of dependencies if they are installed somewhere other than /usr/local/bin/.

update_retrospect_config.plist Place this file in the /Library/LaunchDaemons folder. When you reboot (or run launchctl manually), it instructs launchd to run this script whenever the system configuration changes. This script simply calls the update_retrospect_config script with a parameter indicating that the system configuration has changed. Calls update_retrospect_config. None needed.
update_retrospect_config_reboot.plist Place this file in the /Library/LaunchDaemons folder. When you reboot (or run launchctl manually), it instructs launchd to run this script whenever the system starts up. This script simply calls the update_retrospect_config script with a parameter indicating that the system has just booted. Calls update_retrospect_config. None needed.
update_retrospect_config Called when system configuration changes and also at reboot.

Detects when location has changed.

Selects appropriate Retrospect configuration file, then restarts Retrospect daemon.

This file (update_retrospect_config) is a Unix shell script. It must be saved with Unix line endings, and must have execute permissions. It can be located anywhere, but for several reasons the suggested location is /usr/local/bin (create this directory if it doesn't exist). It relies on two additional files to call it, both of which should be placed in the /Library/LaunchDaemons/ directory: update_retrospect_config.plist and update_retrospect_config_reboot.plist

The two .plist files in the LaunchDaemons directory instruct launchd (part of OS X Tiger) to invoke them whenever the system configuration changes (first file) or the system boots up (second file). Each of these files then calls this script with a parameter indicating why it was called.

This script examines the current location, compares it to the location when this file was last called, and if different, figures out which Retrospect configuration file should be made active. It copies the current configuration file back where it came from, and copies the desired one as the current one, and restarts the Retrospect daemon.

This script uses OS X's extended attribute functionality to save the current configuration file's source, using the handy xattr utility (see this Ars Technica article).

For this to work, you need xattr installed somewhere (I suggest /usr/local/bin, which is where this script looks for it). You also need to run it once on each saved Retrospect configuration file, to store its full path in a new randy_FileWhence extended attribute.

For example, if you have two saved configuration files, retroclient.state.qc and retroclient.state.home, Then run the following commands:

/usr/local/bin/xattr --set "randy_FileWhence" "/Library/Preferences/retroclient.state.qc" /Library/Preferences/retroclient.state.qc

/usr/local/bin/xattr --set "randy_FileWhence" "/Library/Preferences/retroclient.state.home" /Library/Preferences/retroclient.state.home

Customization:

Look for the line case $LOCATION in below. Following this line are the specific names or partial names of locations (in my version of the file these are Pensive* and QC*). These match the computer network Location name that you've created in Network Preferences.

Following each network name is a line that assigns the variable RetroConfigSrc to a file name, such as: /Library/Preferences/retroclient.state.qc. This file name is the name of the specific Retrospect coniguration file to be used for this location. To create this file, install Retrospect as usual, then copy the file /Library/Preferences/retroclient.state as this file, then run the xattr utility to set the randy_FileWhence attribute to the file name (as described above).

So, if you want to have two Retrospect configurations, one for work and one for home:

  1. Set your Location to one of them, say work.
  2. Uninstall Retrospect, then re-install Retrospect.
  3. Copy the default Retrospect conifguration file (as above) to a name specific to this location.
  4. Run the xattr utility to set the randy_FileWhence attribute to the file name (as described above).
  5. Repeat for each location.

This script makes use of the usleep utility to pause for a half-second. If the utility is not installed, it uses the standard sleep utility instead, and waits for a full second.

xattr This command-line utility (not a script) allows access to OS X's extended attribute facility. This allows extended attributes to be set and read by scripts. Source code is available here. See this Ars Technica article for more information. Called by update_retrospect_config. None needed.
usleep Place this executable file in the /usr/local/bin folder. It allows the caller to pause for less than a second. Called by update_retrospect_config. None needed.
usleep.c Source code for the usleep utility. None needed.
format_rfc Shell script front-end for the xml2rfc tool. Requires that the xml2rfc file xml2rfc.tcl exist or be aliased in either the current directory, your home directory, or /usr/local/bin. May need to edit the directory where your xml bibliography files live. The default is individual subdirectories under IETF/bibxml in your home directory. For example, the RFC bibliography files would be in IETF/bibxml/rfc. If you need to change this, look for BIBLIO_DIR.

Uses $EDITOR_WAIT if defined, otherwise $EDITOR. If you use BBEdit and set $EDITOR to bbedit_wrap or bbedit -w, define a new environment variable EDITOR_NOWAIT and set it to just bbedit.

xml2rfc.scpt A BBEdit script (install into ~/Library/Application Support/BBEdit) that runs format_rfc on the front-most BBEdit window. This is especially handy if you bind to a key such as ctrl-x in BBEdit. format_rfc May need to change location of dependencies if they are installed somewhere other than /usr/local/bin/.
smugup-jb.sh

Shell script to upload files to SmugMug site. By default, all files listed or in the specified path that do not already exist in the SmugMug album are uploaded. Can specify which album to upload to.

  • Optionally sets SmugMug caption and keywords from IPTC data.
  • Optionally only checks caption and keywords and updates SmugMug's info if different
  • Optionally uploads only files with a specified Finder label.
  • Optionally uploads all files in the specified path except those with a specified Finder label.
  • Optionally uploads files even if they already exist in the SmugMug album.
  • Optionally saves a password hash to reduce the need to enter password.
Optionally uses GraphicConverter to extract IPTC caption and keywords from image and video files. None needed when standard utilities installed in standard locations.