Does anyone heard about a script to let Safari automatically open all the links located in a web page, either in different tabs, or with different pages ? I have to check pages with more 20 links, and it is a bit tiresome to click twenty times to the links.
Here is a script to open in tabs all links in the html of the front document in Safari.
There are some problems with this script. One being that it doesn’t deal with javascript created links, another being that it only finds links in quotes - I’m sure there are more.
--Script to open page links in Safari tabs
-- John Maisey 16/5/5
--
set myList to {}
tell application "Safari"
set myURL to URL of front document
set URLsource to source of front document
end tell
set {myTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "href=\""}
set myChunks to (text items 2 thru -1 of URLsource)
set AppleScript's text item delimiters to myTID
repeat with myChunk in myChunks
set {myTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "\""}
set myList to myList & (text item 1 of myChunk)
set AppleScript's text item delimiters to myTID
end repeat
repeat with myListNo from 1 to length of myList
set myLink to item myListNo of myList
if myLink does not contain "://" then
set myCount to -2
repeat
if (myLink starts with "../") or (myLink starts with "./") then
set myLink to (characters ((offset of "/" in myLink) + 1) thru -1 of myLink) as text
set myCount to myCount - 1
else
exit repeat
end if
end repeat
set {myTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "/"}
set myBase to (text items 1 thru myCount of myURL) as text
set AppleScript's text item delimiters to myTID
set myLink to (myBase & "/" & myLink) as text
set (item myListNo of myList) to myLink
end if
end repeat
tell application "Safari"
repeat with theURL in myList
my new_tab()
set the URL of document 1 to theURL
end repeat
end tell
--credit http://www.macosxhints.com/article.php?story=20030414185226343
on new_tab()
tell application "Safari" to activate
tell application "System Events"
tell process "Safari"
click menu item "New Tab" of menu "File" of menu bar 1
end tell
end tell
end new_tab
Best wishes
John M
AppleScript: AppleScript 1.9.3
Browser: Safari 312
Operating System: Mac OS X (10.3.9)