Tuesday, November 15 2016

Mac Bash-ing

If you drag URLs around on a Mac, you get .webloc files. If you drag text around (successfully…), you get .textClipping files. Getting data back out of them can be annoying; some applications treat them as attachments, and most insist on grabbing the rich-text version of a clipping rather than the plain text.

webloc () {
  /usr/libexec/PlistBuddy -c 'print URL' "$1"
clipping () {
  DeRez -noResolve -only utf8 "$1" |
    perl -e 'while (<>) {
      next unless s/^\s+\$"([0-9A-F ]+)".*$/$1/;
      tr/ //d;
      $x.= $_;
    print pack("H*",$x),"\n"'