Redshark,
I am not sure I fully understand all of what you request but I have been looking at a possible solution to your inquiry.
The AppleScript dictionary of Firefox will not allow you to do what you want as it has no properties or commands related to tabs.
It is also difficult to get that information directly through probing the application using System Events GUI scripting.
Therefore you can not determine anything about the tabs such as their number, titles, size, location and the solution becomes rather involved and somewhat rough.
Using some of the other capabilities of System Events it is possible to piece together a rough solution that will count the number of tabs, move between tabs, and eliminate specified duplicates/empty tabs.
Without knowing the number of tabs it is difficult to provide a solution. There are at least two ways of determining the number of tabs.
1) Ask the user initially and then keep track;
2) Set a marker at the end of the tabs.
I have arbitrarily set a marker tab, which in my case is an empty tab i.e., no URL, at the end of all the other tabs so that I can determine the number of tabs.
NOTE: This means that there should not be any empty tabs in the middle.
The testing is based on the name of the window, determined using AppleScript, which reflects the name of the tab.
The program does the following:
1) checks for a marker tab at the end of the tabs and creates one if it is missing;
2) eliminates all of the duplicated tabs;
2) opens the Google News in a new tab;
3) creates a new marker tab at the end of the tabs.
click here to
open this script in your editor
<pre style="font-family: 'Monaco', 'Courier New', Courier, monospace; overflow:auto; color: #222; background: #DDD; padding: 0.2em; font-size: 10px; width:400px">property theTabNames : {}
property WantedURL : "http://news.google.com"
property MarkerTabName : "Mozilla FireFox"
property DuplicateNames : {"Google News", MarkerTabName}
on run {}
my SetMarkerTab()
-- Remove duplicate names
repeat with i from 1 to count of items in DuplicateNames
set theTabNames to my DetermineNumberOfTabs(MarkerTabName)
my EliminateTabs(theTabNames, item i of DuplicateNames)
end repeat
-- Open tab with wanted URL
tell application "Firefox"
Get URL WantedURL
end tell
-- Reset the marker
my CreateMarkerTab()
end run
on SetMarkerTab()
tell application "System Events"
tell process "firefox-bin"
set frontmost to true
keystroke "9" using command down -- move to last tab
if (name of window 1) is not MarkerTabName then my CreateMarkerTab()
end tell
end tell
end SetMarkerTab
on DetermineNumberOfTabs(MarkerName)
tell application "System Events"
tell process "firefox-bin"
set frontmost to true
set i to 1
set theNames to {}
set LastTabName to ""
repeat until LastTabName is equal to MarkerName
keystroke (i as string) using command down -- move to a tab
set LastTabName to name of window 1
set theNames to theNames & LastTabName
set i to i + 1
end repeat
end tell
end tell
return theNames
end DetermineNumberOfTabs
on EliminateTabs(TabNames, DuplicateName)
tell application "System Events"
tell process "firefox-bin"
set frontmost to true
repeat with i from (count of TabNames) to 1 by -1
if (item i of TabNames) is equal to DuplicateName then
keystroke (i as string) using command down -- move to a tab
keystroke "w" using command down -- close a tab within a window
end if
end repeat
end tell
end tell
end EliminateTabs
on CreateMarkerTab()
tell application "System Events"
tell process "firefox-bin"
set frontmost to true
keystroke "t" using command down -- new tab
end tell
end tell
end CreateMarkerTab
</pre>
PowerBook 12" Mac OS X (10.4.8)