AppleScript for NYT crossword

Discussion in 'Mac Programming' started by sonicseamus, Sep 8, 2012.

  1. sonicseamus macrumors newbie

    Jul 31, 2012
    Washington, DC
    Hey guys, I've recently been trying to create an automator/applescript action that downloads the NYTimes crossword of the day and prints it out. I think I know how to do most of it, but I'm stuck on one part. Here's the problem:

    The nytimes crossword is posted daily as a pdf at a URL in this format: (xxxx)/month (xx)/day (xx)/month (1st three letters) day (xx) year (xx).pdf

    An example:

    Basically I want to create an Applescript that goes to a URL of this format based on the current date.

    I know the "current date" variable, but I'm unsure how to convert it into variables for the various forms that are in the URL. Also, I don't know how to insert variables into an open location command.

    Is it possible to build the URL and then insert it into the open location command as one large variable?

    Thanks for any advice,

  2. Red Menace macrumors 6502

    Red Menace

    May 29, 2011
    Littleton, Colorado, USA
    An AppleScript date object has several properties, so it is just a matter of putting them together into the desired string, for example:

    property baseLink : ""
    tell (current date)
    	set theYear to (its year as text)
    	set monthName to text 1 thru 3 of (its month as text)
    	set theMonth to text -2 thru -1 of ("00" & (its month as integer)) -- leading zero
    	set theDay to text -2 thru -1 of ("00" & (its day as text)) -- leading zero
    end tell
    set theLink to baseLink & theYear & "/" & theMonth & "/" & theDay & "/" & monthName & theDay & (text -2 thru -1 of theYear) & ".pdf"
    return theLink

Share This Page