Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

sonicseamus

macrumors newbie
Original poster
Jul 31, 2012
3
0
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:

http://select.nytimes.com/premium/xword/year (xxxx)/month (xx)/day (xx)/month (1st three letters) day (xx) year (xx).pdf

An example:

http://select.nytimes.com/premium/xword/2012/09/08/Sep0812.pdf

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,

Seamus
 
An AppleScript date object has several properties, so it is just a matter of putting them together into the desired string, for example:

Code:
property baseLink : "http://select.nytimes.com/premium/xword/"

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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.