Applescript to click a link

Nov 01, 2005 22:11

I am writing an Applescript to launch a music stream from iCal. Is there a way to click the 23 link on a page? I can't just open the URL because its a special pop-up window. (I've already tried grabbing the URL from the source but it doesnt work that way ( Read more... )

Leave a comment

Comments 5

xv November 2 2005, 07:25:08 UTC
You can do this with Safari's do Javascript command, but you need to know the index number of the button/link in the document object model of the page. There are several ways to get at this information, but none of them afaik are as simple as "click the 23rd link." If you could link us to the page in question it'd be easier to prescribe a solution...

Reply

cyclotron November 2 2005, 07:46:33 UTC
solved it

Reply


xv November 2 2005, 09:45:58 UTC
Ah, good. That's a much better solution than the DOM approach. It seems to me though that the first step is unnecessary. The JS code in the last half of your script should execute on any page that's loaded in Safari. If no pages are open you could at least avoid setting an arbitrary delay by opening a blank file directly off the hard drive.
open location "file:///" & POSIX path of (path to desktop folder) & "blank.html"

Reply

xv November 2 2005, 09:55:10 UTC
...or this, which doesn't require a file:
tell application "Safari"
make new document at front of documents with properties {URL:"about:blank"}
end tell

Reply

cyclotron November 2 2005, 09:56:07 UTC
Yeah - I thought the first step was unnecessary too, but I think that streamaudio.com is checking for a referring page. Just a guess. Otherwise the audio doesnt seem to load. You are welcome to try it and verify my speculation.

Reply


Leave a comment

Up