Get List of URLs of Safari Documents with specified content

Hi @All,

I need an AppleScript which gets all URLs of a Safari document and then opens all URLs which contains a specified String. The String is just a part of the URL. Then it should be possible to send all open Safari windows by Mail, isn’t it? My problems are:

Is there a type like URL_List? Or how to get all URLs from a Safari document? How is it possible to check if the URL contains a specified String. How to open every document of the URL List?

I get crazy with the documentation of AppleScipt :rolleyes:

My current script has to be changed because the site I used to get information from subsites changed and now the subsites are not just different by an integer in the URL but by a document number the URL contains, too.
Therefor I must use another method than before. I perform a search which results in a list of links to documents. All these documents need to be send by mail. I want to script that by getting the URLs open them in different Safari Documents and send every open Safari Document by Mail. Do you think that will work or do you have another idea?

I have to send about 100 Mails a day this way and it would be very cool, to have a script doing that again.

Thanks for your help

Greetz

ragob66

Hi ragob66,

here’s how you can use JavaScript in an AppleScript to build a linklist from the frontmost Safari document:


property javaScriptCode : " 
numLinks=document.links.length; 
linkList=''; 
linkList= document.links[0];
for (i=1; i<numLinks; i++) { 
linkList= linkList + ' ' + document.links[i]; 
} 
"

tell application "Safari"
	
	set linksFromPage to do JavaScript javaScriptCode in document 1
	
end tell

For the second part - I am afaid i didn’t understand fully . But it might be an idea to write a shell script for filtering and downloading the URLs (with ‘grep “Searchstring”’ and curl -O URL) and implement it in your AppleScript? Or maybe you can do the URL filtering within the JavaScript …

Hope this helps :slight_smile:

D.