• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Previous APOD Page
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Previous APOD Page


  • Subject: Re: Previous APOD Page
  • From: Christopher Stone <email@hidden>
  • Date: Thu, 30 Aug 2012 04:18:41 -0500

Hey Folks,

Here's the latest incarnation of the APOD script.

I finally figured out how to make the Unix date command accept a date in a specific format and output to a different format and was also able to make it adjust by -1 day in one fell swoop.

I decided to go with Nigel's method of using the date embedded in the page url, but I've cased for the possibility of the astropix page.

If the script opens a new document it blows it up to full-screen using the size of the Desktop's window, so people with multiple or large monitors might need to make adjustments.

--
Best Regards,
Chris

------------------------------------------------------------------------------------------------
#       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
  if _url does not start with "http://apod.nasa.gov/apod/" then
    set newDoc to make new document with properties {URL:"http://apod.nasa.gov"}
    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
        set newURL to do shell script "echo 'http://apod.nasa.gov/apod/ap'`date -v -1d -jf \"%y%m%d\" " & "\"" & _date & "\" \"+%y%m%d\"`.html"
      else
        set _src to quoted form of (get source)
        set newURL to do shell script "
             APOD=http://apod.nasa.gov/apod/ap;
             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
------------------------------------------------------------------------------------------------

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Previous APOD Page (From: Christopher Stone <email@hidden>)

  • Prev by Date: Re: Apache-Apple Event Bridge
  • Next by Date: Re: Previous APOD Page
  • Previous by thread: Re: Previous APOD Page
  • Next by thread: Re: Previous APOD Page
  • Index(es):
    • Date
    • Thread