Reputation: 1051
I am trying to write an AppleScript that, among other things, gets the URL of every open webpage in Firefox.
In Safari (and Chrome), this is done very simply:
tell application "Safari" to return URL of every tab in every window
However, it seems to me that Firefox offers no real AppleScript support, such as for getting the URL of any tab or window. When I google the terms "Firefox" and "AppleScript" together, I mostly get Firefox bug requests asking for AppleScript support to be restored, last updated in 2010 or 2011 (like this and this).
Am I right in thinking, then, that Firefox no longer offers any proper AppleScript support? I realize that there are some semi-workarounds, such as simulating key-commands in AppleScript, but those aren't really practical for my purposes.
Upvotes: 5
Views: 4630
Reputation: 16575
This works in Firefox. It's not all that pretty, though :)
tell application "Firefox"
activate
tell application "System Events" to keystroke "1" using command down
set firstTitle to name of front window
set tabList to {}
set myTitle to "__f_o_o_b_a_r__" -- some random initial name
set counter to 0 -- make sure that loop ends
repeat until (counter > 100 or myTitle is equal to firstTitle)
tell application "System Events" to key code 121 using control down
tell application "System Events" to keystroke "l" using command down
tell application "System Events" to keystroke "c" using command down
delay 0.1
set myTitle to (name of front window)
copy (the clipboard) to the end of the |tabList|
set counter to counter + 1
end repeat
end tell
tabList
I use a similar approach when searching for tabs using a global shortcut.
Upvotes: 0
Reputation: 69
The Firefox team has been working on this, apparently since 2002
In the meantime, you can use UI programming to get the URL of the frontmost tab
tell application "System Events" to tell process "Firefox"
get value of text field 1 of combo box 1 of toolbar 2 of group 1 of front window
end tell
Works with version 68.0.2 but will probably be broken in some future update to Firefox.
Upvotes: 1
Reputation: 2030
Firefox 3.5 and earlier supported this, even though the command was not visible in the dictionary:
tell application "Firefox"
get «class curl» of window 1
end tell
Firefox 3.6 removed this feature, and as of now (Firefox 22.0) it has not been restored.
Upvotes: 2
Reputation: 4421
To see all of the AppleScript commands that Firefox responds to, launch AppleScript Editor, select the menu File > Open Dictionary...
, and choose the Firefox application.
You'll find what you're expecting: Firefox doesn't offer any useful AppleScript commands.
Upvotes: 8