------------------------------------------------------------------------------------------------
# Author: Christopher Stone
# Created: 2012-08-30 : 12:05
# Modified: 2012-08-30 : 03:36
# Application: Safari, Shell: awk, date, sed
# Purpose: Open Today's APOD if front Safari Document is not on that domain.
# If on APOD domain go to previous APOD page.
------------------------------------------------------------------------------------------------
tell application "Finder" to set desktopBounds to bounds of window of desktop
tell application "Safari"
set _url to URL of front document
set bounds of front window to desktopBounds
else
tell front document
set _date to do shell script "echo " & _url & "| awk -F'/apod/ap' '{ print $2 }'| awk -F. '{ print $1 }'"
if _date ≠ "" then
else
set _src to quoted form of (get source)
set newURL to do shell script "
D1=`echo " & _src & " | sed -En 's/(^ *[0-9]{4} [a-zA-Z]+ [0-9]{2}) */\\1/p'`;
D2=`date -v -1d -jf \"%Y %B %d\" \"$D1\" \"+%y%m%d\"`;
echo $APOD$D2.html;"
end if
set URL to newURL
end tell
end if
end tell
------------------------------------------------------------------------------------------------