i want to get the url of the frontmost tab, Firefox or other Modzilla browsers. I tried:
tell window 1 of application "Firefox"
set the_url to get_url()
end tell
(*
on get_url()
return (do javascript "window.location.href")
end
*)
Haha, would be nice to interact with Javascript within Applescript - a very outdated osax enabled javascript. In Yosemite and up, we can select Javascript as alternative scripting language, but i want interaction between both languages -
Unluckily i have no idea how to get the url of the front tab.
-- If running this script using Command-r in Script Editor, tap and release the "r" key very quickly!
-- Store the current clipboard contents.
set theClipboard to (the clipboard as record)
-- Set the clipboard to a default blank value
set the clipboard to ""
-- Bring Firefox to the front, highlight the URL in the URL field and copy it.
tell application "System Events"
set frontmost of application process "firefox" to true
keystroke "lc" using {command down}
end tell
-- Read the clipboard contents until either they change from "" or a second elapses.
repeat 5 times
delay 0.2
set theURL to (the clipboard)
if (theURL ≠"") then exit repeat
end repeat
-- Restore the old clipboard contents.
set the clipboard to theClipboard
theURL
first, thank you Nigel for your prompt answer. Its an unusual style to see you using UI scripting, i thought this is Yvan at a quick look. Probably yours is the best way to approach this situation.
ccstone, you are right. But with badly or not scriptable apps we can go “artistic” with some workarounds. Sometimes funny, not always.
The best solution here would be to use Javascript, but ive very. few experience to combine something in Js.
Since i use Macs, i never understood why browsers dont tag downloaded files with the source url address. Previous versions of Opera or Modzilla browsers supported some more scripting. Why they removed that, no idea.
If i look what macs out of the box do and what i did with scripts, i have just to smile. Could not use macs without scripting.
This is one reason Keyboard Maestro is an indispensable automation tool on my system.
JavaScript cannot be accessed in Firefox via AppleScript “ you’ll need something like the GreaseMonkey Firefox extension. (I have no experience with it and cannot advise.)
Safari and Google Chrome DO properly embed kMDItemWhereFroms in downloaded files metadata “ frankly I’m shocked that Firefox does NOT.
It looks like there are ways to add it in if you want to badly enough “ search Google for “Firefox wherefrom”.
Their stated reason is “security” to which I reply “Bollocks!”
Agreed.
A Mac without scripting and automation is about as useful as a balsa wood boat anchor…