Create a automated script with variable link

Hello

I am trying to create a script with Automator or Applescript which I would use every day, and basically it would allow me to open a link in a new window in Safari, but the link would change every day with the date of the day I am opening it.

For example:

Today (16/05/2012) the link would look like this: http://website.com/folder/name_of_the_file16052012.html

Tomorrow the link would be: http://website.com/folder/name_of_the_file17052012.html

The day after it would be: http://website.com/folder/name_of_the_file18052012.html

And so on…

My question is: Is there a way to write the script so that when opening the link ti automatically determines the date and puts it in the link? OR the other option would be for a dialog to pop up asking me the date, I would type 16052012 and that would be the final part of the link to open.

I hope I made it clear!

Thank you for your help.

Hi,

try this


property baseURL : "http://website.com/folder/name_of_the_file "

set theDate to do shell script "date +%d%m%Y"
set {button returned:buttonReturned} to display dialog "" buttons {"Cancel", "Open Link of Date.", "Open Link of Today"}
if buttonReturned is "Open Link of Date." then
	set {text returned:theDate} to display dialog "Enter Date with format ddmmyyyy" default answer today
end if
open location (baseURL & theDate & ".html")

WOW! Thank you for your QUICK and efficient answer! I love this place :smiley:

One question: What if I wanted to open different pages like that, for example:

http://website.com/folder/name_of_the_first_file16052012.html
http://website.com/folder/name_of_the_second_file16052012.html
http://website.com/folder/name_of_the_third_file16052012.html

Thank you!! :wink:

something like this


property URL_list : {"http://website.com/folder/name_of_file1 ", "http://website.com/folder/name_of_file2 ", "http://website.com/folder/name_of_file3 "}

set baseURL to choose from list URL_list
if baseURL is false then return

set theDate to do shell script "date +%d%m%Y"
set {button returned:buttonReturned} to display dialog "" buttons {"Cancel", "Open Link of Date.", "Open Link of Today"}
if buttonReturned is "Open Link of Date." then
	set {text returned:theDate} to display dialog "Enter Date with format ddmmyyyy" default answer today
end if
open location (item 1 of baseURL & theDate & ".html")

Oh ok, but that would open only 1 link that I choose from the list, what if I wanted to open all links in different tabs?

(Sorry if I explained myself incorrectly)


property URL_list : {"http://website.com/folder/name_of_file1", "http://website.com/folder/name_of_file2", "http://website.com/folder/name_of_file3"}

set theDate to do shell script "date +%d%m%Y"
set {button returned:buttonReturned} to display dialog "" buttons {"Cancel", "Open Link of Date.", "Open Link of Today"}
if buttonReturned is "Open Link of Date." then
	set {text returned:theDate} to display dialog "Enter Date with format ddmmyyyy" default answer today
end if
repeat with anURL in URL_list
	open location anURL & theDate & ".html"
end repeat

Thank you very much!

Ok so I have created, from your great suggestions, the following script:


property URL_list : {"http://website.com/folder1/folder2/"}


set theDate to do shell script "date +%Y/%m/%d"
set baseURL1 to "/pages/1.html"
set baseURL2 to "/pages/2.html"
set baseURL3 to "/pages/3.html"
set baseURL4 to "/pages/4.html"
set baseURL5 to "/pages/5.html"

repeat with anURL in URL_list
	open location anURL & theDate & baseURL1
	open location anURL & theDate & baseURL2
	open location anURL & theDate & baseURL3
	open location anURL & theDate & baseURL4
	open location anURL & theDate & baseURL5
end repeat

So this opens me the 4 webpages of the folder in that particular date.

Now, I know the following is possible in automator (at least for one tab): I would like to recall each one of the 5 tabs and tell on each tab to recall the articles URLs, as they are all entries in blog style.+

Is that possible with Applescript?

Thank you

do you mean this?


property baseURL : "http://website.com/folder1/folder2/"
property URL_list : {"/pages/1.html", "/pages/2.html", "/pages/3.html", "/pages/4.html", "/pages/5.html"}

set theDate to do shell script "date +%Y/%m/%d"
tell application "Safari"
	if (count documents) is 0 then make new document
	repeat with anURL in URL_list
		set theLocation to baseURL & theDate & anURL
		tell window 1
			try
				set theTab to (1st tab whose URL ends with contents of anURL)
			on error
				set theTab to make new tab at end of tabs with properties {URL:theLocation}
			end try
		end tell
		set URL of theTab to theLocation
	end repeat
end tell


Hmmm… not really, because that is just another way to rewrite the code, but the outcome is the same.

Automator has a feature in its list that allows you to open in different tabs all links of the articles within that open web page.

I have attached a screenshot of the rule set with Automator to understand.

I was wondering if it was possible to do the same with this script, so that I can include everything is the Applescript workflow.

Uploaded with ImageShack.us

you didn’t mention that you want to gather the links from a website.
I think it’s possible but a bit more complicated

Ya I thought I express myself badly… :frowning: sorry…

Hi Stefan,

Quick question: in the script above, if I click on “Open Link of Date.” the execution gives me an error, and I cannot write down a date, how come?

The error says, the variable today is not defined, replace today with theDate


.
 set {text returned:theDate} to display dialog "Enter Date with format ddmmyyyy" default answer theDate
.