Hi,
I was trying to get an apple script to open one of my links on my website. I have tried many things, but I just can’t figure it out. Could you maybe help me out? I was trying to have it open the link called Awesome Biking.
Thanks.
set site to "http://www.zandersite.co.nr"
repeat
open location site
delay 3
open "Awesome Biking"
delay 10
tell application "Safari"
quit
end tell
end repeat
set site_url to "http://macscripter.net/"
set link_text to "AppleScript | OS X"
tell application "Safari"
activate
open location site_url
-- wait until page loaded
if my page_loaded(20) is false then error numner - 128
-- get number of links
set num_links to (do JavaScript "document.links.length" in document 1)
-- find the link
set c to num_links - 1
set this_link to ""
set f to false
repeat with i from 0 to c
set this_link to do JavaScript "document.links[" & i & "].text" in document 1
if this_link is link_text then
set f to true
exit repeat
end if
end repeat
if f then -- link text found
-- get the url and open the link url
set link_url to do JavaScript "document.links[" & i & "].href" in document 1
open location link_url -- opens in new page
else
display dialog "Link \"" & link_text & "\" not found."
end if
end tell
--
on page_loaded(timeout_value)
delay 2
repeat with i from 1 to the timeout_value
tell application "Safari"
if (do JavaScript "document.readyState" in document 1) is "complete" then
return true
else if i is the timeout_value then
return false
else
delay 1
end if
end tell
end repeat
return false
end page_loaded
I’m using an old version of Safari, so it doesn’t have GetURL.
tell application "Safari"
activate
try
set _exists to document 1
tell front document
set URL to "http://www.zandersite.co.nr"
end tell
on error
make new document
tell front document
set URL to "http://www.zandersite.co.nr"
end tell
end try
end tell
You can’t get the url from the link text “,Awesome Biking,” because it’s not on the page. “,Awesome Biking,” is in your html document for the frame. You would have to go to the html document for the frame. The google one. You would need to search every frame’s document.
I wonder why open location doesn’t work in the new versions of Safari anymore. It must be erroring or something. See Peter’s ‘set url’ of front document method instead of open location in the Safari tell block.
if you use the URL of the main frame : [i]http://zslavitz.googlepages.com/[/i]
and the value of the variable link_text “,Awesome Biking,”, then kel’s script works
set site_url to "http://zslavitz.googlepages.com/"
set link_text to ",Awesome Biking,"
tell application "Safari"
...