The UNIX shell provides a host of extremely useful utilities for modifying text. This OS X Automator service makes all of them available for filtering text in all OS X applications.
This can be handy for performing quick operations, like replacing text with regular expressions, sorting lists or swapping fields around.
When triggered, the service requests a command to use for filtering, then runs the command and replaces the selected text with the result.
Some sample operations:
- Sort lines alphabetically/numerically: sort or sort -n
- Change to lowercase: tr "[:upper:]" "[:lower:]"
- Replace a spelling mistake, taking care of case: sed -E 's/([tT])eh/\1he/g'
- Re-order elements in a tab- or comma-separated list: awk '{print $2 $1}' or awk -F, '{print $2 "," $1}'
Put it in Library/Services
, and it should appear in the ‘Services’ menu.
Resuming ADC downloads (‘cos Safari sucks)
So, Safari’s resume facility is just awful — it’ll randomly restart downloads from the beginning, clobbering anything that’s already been downloaded, and the resume button will frequently disappear entirely and mysteriously from the downloads window. And if the session has expired, it’ll cause all kinds of havoc.
Anyone downloading the gazillion-gb iOS/Mac SDK + XCode on a slow and/or expensive connection will know the sheer fisticuffs-inspiring irritation this creates — speaking personally, living on a mobile broadband connection that’s usually changed at £3 per gig and often runs about as fast as I could send the data via carrier pigeon, this usually makes me want to storm Cupertino with a pitchfork.
Okay, so I could probably use Firefox or something else, but instead I figured I’d whip up* a shell script that lets me use my favoured long-haul download tool – curl. And in case there were any other sufferers of insanely-priced broadband and Safari’s antisocial behaviour, I thought I’d share it.
It’ll ask for your Apple ID and password, and store it in the keychain for you, and it’ll resume from the current working directory.
Chuck it somewhere like
/usr/local/bin
, make sure it’s executable (chmod +x /usr/local/bin/adc_download.sh
) and call it from Terminal like:adc_download.sh https://developer.apple.com/devcenter/download.action?path=/Developer_Tools/xcode_4_gm_seed/xcode_4_gm_seed_.dmg
If you’ve already started the download in Safari, just grab the partially-downloaded file from within the .download package Safari creates.
Here ’tis:
ADC Download Script (on Github)
P.S. I’d be interested to see how incremental updates fare when transferred from an intermediate server with rsync. It’s rather bizarre that Apple reissue the whole 3.x gb SDK with each update, rather than offering a ‘patch’ (I guess Apple lives blithely in the world of cheap bandwidth!), and it makes me wonder whether there’d be sufficient correlation between versions to save some bandwidth by avoiding transferring the similarities…
* read: spend hours on, as is my way.