cURL / Mailing Lists / curl-users / Single Mail

curl-users

Curling Apples

From: Doug McNutt <douglist_at_macnauchtan.com>
Date: Fri, 7 Sep 2012 17:39:52 -0600

To curl in Mac OSX one needs to put aside the brooms and irons.

Christopher Stone posted a technique for using AppleScript to recover a file that AppleScript really didn't want to deliver by itself. With his permission. . .

AppleScript supports IPC in ways that other UNIX-based systems are lacking. DBUS isn't close and tools like pbpaste (report the contents of the clipboard in stdout) and pbcopy (copy the argument into the clipboard) are non-existent.

An Applescript can be saved as a double-clickable file in Apple's OS neXt and it supports a "do shell script" command that creates a new instance of bash which knows nothing about your environment settings or even your current working directory. Such a file can be executed by a user infected with the $terminal =~ $panic syndrome.

These offerings by Chris are worthy of note. Personally I never even thought of piping to sed and awk as a means of creating a curl command.

do shell script "U=http://apod.nasa.gov/apod/;cd ~/Desktop;curl -LOs `curl -Ls $U|awk -v U=$U -F\\\" '/a.href=\"image/{print U$2}'`"

do shell script "cd ~/Desktop && curl -LOs `curl -s <http://apod.nasa.gov/apod/>http://apod.nasa.gov/apod/ | sed -En 's|.+a.href=\"(image[^\"]+).+|<http://apod.nasa.gov/apod/\\1|p'>http://apod.nasa.gov/apod/\\1|p'`"

do shell script "
        bURL=\"<http://apod.nasa.gov/apod/\>http://apod.nasa.gov/apod/\";
        uPTH=`curl -s \"$bURL\" | awk -F\\\" '/href=\\\"image/ { print $2 }'`;
        uNM=`awk -F/ '{ print $NF }' <<< $uPTH`;
        curl -s \"$bURL$uPTH\" -o ~/\"Pictures/APOD_Images/`date '+%Y%m%d » '`$uNM\";

do shell script "
        mkdir ~/Pictures/APOD_Images 2>/dev/null;
        bURL=\"<http://apod.nasa.gov/apod/\>http://apod.nasa.gov/apod/\";
        uPTH=`curl -s \"$bURL\" | awk -F\\\" '/href=\\\"image/ { print $2 }'`;
        uNM=`awk -F/ '{ print $NF }' <<< $uPTH`;
        curl -s \"$bURL$uPTH\" -o ~/\"Pictures/APOD_Images/`date '+%Y%m%d » '`$uNM\";

-- 
1801 - Joseph Marie Jacquard uses punch cards to instruct a loom to weave "hello, world" into a tapestry.
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-users
FAQ:        http://curl.haxx.se/docs/faq.html
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2012-09-08