Re: Getting the URL
Re: Getting the URL
- Subject: Re: Getting the URL
- From: "Jonathan Levi, M.D." <email@hidden>
- Date: Thu, 19 Jul 2007 08:48:52 -0400
On Thu, 19 Jul 2007 11:53:08 +0200, Emmanuel
<email@hidden> wrote:
Message: 8
Date: Thu, 19 Jul 2007 11:53:08 +0200
From: Emmanuel <email@hidden>
Subject: Re: Getting the URL
To: email@hidden
Message-ID: <p06230903c2c4e481a1ed@[10.0.1.4]>
Content-Type: text/plain; charset="us-ascii" ; format="flowed"
At 2:12 PM -0700 7/18/07, Mike wrote:
Is there a standard way in AppleScript to get the current URL from
the active window in a web browser?
There is not one technique for all browsers. I know for two
Webkitters, Safari:
tell app "Safari" to get URL of document 1
and Smile:
tell app "Smile" to get path name of window 1
The following subroutine, using GUI-scripting, causes Firefox to get
the URL of its front window (I use it for only one purpose, it could
possibly cause errors elsewhere):
-----------------------------------------------------------------------------
on GetURLName()--do shift-tab and copy results until clipboard contains a URL
tell application "System Events" to tell process "firefox-bin"
set theURL to ""
set the clipboard to ""
repeat 20 times
keystroke tab using shift down
click menu item "Select All" of menu "Edit" of menu bar item
"Edit" of menu bar 1
click menu item "Copy" of menu "Edit" of menu bar item "Edit"
of menu bar 1
try --may be impossible to coerce clipboard contents to a string
if (((the clipboard) as string) starts with "http") then
set theURL to the clipboard
exit repeat
end if
end try
end repeat
end tell
(the clipboard) as string
end GetURLName
-----------------------------------------------------------------------------
I suspect a more universal script could be attained using a
custom-made HTML file containing JavaScript, but I don't know this.
Perhaps someone versed in JavaScript could comment.
Jonathan
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden