Re: getting source in default web browser
Re: getting source in default web browser
- Subject: Re: getting source in default web browser
- From: matt neuburg <email@hidden>
- Date: Mon, 14 Apr 2003 05:48:29 -0700
On Sun, 13 Apr 2003 23:45:25 +1000, John Cochrane
<email@hidden> said:
>
tell application "Safari"
>
set vText to text of document 1
>
set vtitle to name of window 1
>
copy the source of the front document to vContent
>
end tell
>
>
Of course to work properly this needs a page open in Safari.
>
To make the script portable I was trying to use the default browser to
>
achieve the same thing with
>
tell application browserName
>
activate
>
set vText to text of document 1
>
set vtitle to name of window 1
>
--the above 2 lines work fine
>
--but if I try
>
copy the source of the front document to vContent
>
-->this line gets an error
>
end tell
>
>
Does anyone know why the error occurs and how to get the source of the
>
page?
The problem is that "browserName" is not known until runtime, but the
phrase "the source of the front document" is a Safari-defined notion and
can only be compiled in relation to Safari. Look in the Safari dictionary
- "source" is part of the "Safari suite". AppleScript must look there too,
in order to compile your script. But you are not telling it Safari's name,
so it can't.
So, we learn two things:
(1) You can't compile a script for which AppleScript doesn't have the
dictionary terms. This is why they gave you "using terms from". See:
http://www.applescriptsourcebook.com/tips/tellbyvariable.html
(2) Your attempt to use this script generically is probably doomed to
failure anyway, because each browser likely has a different way of being
told to get the source of the current page. You're going to have to write
different scripts for different browsers.
m.
matt neuburg, phd = email@hidden,
http://www.tidbits.com/matt
pantes anthropoi tou eidenai oregontai phusei
Subscribe to TidBITS! It's free and smart.
http://www.tidbits.com/
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.