I have an existing AppleScript program that searches Safari windows and tabs for a specific URL but wanted the same thing for Firefox. I simply opened the FindSafariTab.app in Script Debugger and changed “Safari” to “Firefox” and then try to compile but get and error saying “expected class name but found property” on the line “set tablist to every tab of win” – here is the complete listing:
set question to display dialog ("Find Firefox tab:") default answer ""
set searchpat to text returned of question
with timeout of 1200 seconds
tell application "Firefox"
set winlist to every window
set winmatchlist to {}
set tabmatchlist to {}
set tabnamematchlist to {}
repeat with win in winlist
set ok to true
try
set tablist to every tab of win
on error errmsg
--display dialog name of win as string
set ok to false
end try
if ok then
if (tablist is not missing value) then
repeat with t in tablist
if searchpat is in (name of t as string) then
set end of winmatchlist to win
set end of tabmatchlist to t
set end of tabnamematchlist to (id of win as string) & "." & (index of t as string) & ". " & (name of t as string)
--display dialog name of t as string
else if searchpat is in (URL of t as string) then
set end of winmatchlist to win
set end of tabmatchlist to t
set end of tabnamematchlist to (id of win as string) & "." & (index of t as string) & ". " & (name of t as string)
--display dialog name of t as string
end if
end repeat
end if
end if
end repeat
if (count of tabmatchlist) = 1 then
--display dialog "one!"
set w to item 1 of winmatchlist
set t to item 1 of tabmatchlist
set current tab of w to t
set index of w to 1
else if (count of tabmatchlist) = 0 then
display dialog "No matches"
else
set whichtab to choose from list of tabnamematchlist with prompt "The following tabs match, please select one:"
set AppleScript's text item delimiters to "."
if whichtab is not equal to false then
set tmp to text items of (whichtab as string)
set w to (item 1 of tmp) as integer
set t to (item 2 of tmp) as integer
set current tab of window id w to tab t of window id w
set index of window id w to 1
end if
end if
end tell
end timeout
Any idea what is causing the compile error? Version of Firefox is 89.0.1 if it matters…and my macOS version is High Sierra, aka 10.13.6 and my version of Script Debugger is 7.0.13
Not sure why the first few lines and the last couple of lines didn’t get included in the scrolling portion of the post along with the rest of the AppleScript code - what did I do wrong? Thanks again…
the programs starts with “set question…” line and ends with “end timeout” lines
Hi, Bob, the issue is that Firefox is not AppleScriptable. It doesn’t have an appleScript dictionary.
Right now I believe the only browsers that have AppleScript dictionaries are Safari, Chrome and Opera (if that’s still around). There may be others.
Usually moving a script from controlling one application to another requires some tweaking (often a lot). But going back and forth between Safari and Chrome is usually pretty simple.
But with Firefox you’re pretty much out of luck. No AppleScript support.
This is not quite true – Firefox does have an AppleScript dictionary.
Although it’s only Apple’s standard suite and has no Firefox-specific objects or commands.
This means an inexperienced user can drop Firefox on Script Debugger or the Apple Script Editor – see it has a dictionary – and think it can be scripted.
You can do trivial stuff like this with Firefox:
tell application "Firefox"
set bounds of front window to {228, 23, 1542, 1196}
set winNameList to name of windows
end tell
But you can’t delve much deeper – even with UI-Scripting.
Rule-of-the-thumb – AETD (Always Examine The Dictionary) before you beat your head against the wall trying to script something that can’t be scripted.
Thanks very much to both Ed and Christopher - bummer, but that’s the way the cookie crumbles I guess Appreciate the help very much. This is one of the best forums to go to to get great information. Kudo’s to all those who help out everyone.
Interesting. Before I responded I dropped the Firefox Icon on SD and it didn’t work. I also tried the Open Dictionary command and the Firefox icon was dimmed.
Maybe my Firefox is out of date? (72.0.2)
→ Script Debugger 7.0.13 (7A125)
→ Mac OS 10.11.6 (15G22010)
I have a golden nugget for all of you. Download the new Brave Browser and open its scripting dictionary in Script Debugger and tell me if it fits the bill for what was attempted in this thread.
You may like what you find. Here is the link: Brave Browser - w/AppleScript Support