------------------------------------------------------------------------------------------------
# Created: 2012-08-27 : 08:27
# Modified: 2012-08-27 : 09:02
# Application: The Shell, Egrep, Curl, Sed
# Purpose: Download Today's APOD.
------------------------------------------------------------------------------------------------
try
set apodPicFldr to do shell script "echo ~/Pictures/APOD_ƒ/"
try
alias POSIX file apodPicFldr
on error
do shell script "mkdir " & apodPicFldr
end try
set apodImg to do shell script "curl -Ls --user-agent 'Opera/9.70 (Linux ppc64 ; U; en) Presto/2.2.1' \"" & apodRoot & "\" | egrep -i \"href="" | sed -E 's/[^\"]+\"([^\"]+)\".*/\\1/'"
paragraphs of apodImg
if length of result = 1 then
set apodImgName to do shell script "echo `date \"+%y%m%d\"`-`sed -E 's|.+/(.+)$|\\1|' <<< " & quoted form of apodImg & "`"
set apodImgDldPath to "\"" & apodPicFldr & apodImgName & "\""
set apodImgURL to "\"" & apodRoot & apodImg & "\""
do shell script "curl -L --user-agent 'Opera/9.70 (Linux ppc64 ; U; en) Presto/2.2.1' --url " & apodImgURL & " -o " & apodImgDldPath
else
# BAIL!
end if
on error eMsg number eNum
tell me to display dialog eMsg & return & return & eNum
end try
------------------------------------------------------------------------------------------------