My goal - in doing research on various topics I sometimes open 50+ browser tabs. When finished I want to iterate over the list of tabs and save the urls.
I can start with a tab, get the URL and then move on to the next. That part is easy enough. I can't figure out how to tell when I've come to the end? My recovering programmer brain wants there to be a function: hasNextTab().
Bonus Points - is there an elegant way to ignore pinned tabs? I could just start the first tab at 3, knowing I always have two pinned tabs.
tell application "Safari"
set windowCount to number of windows
set docText to ""
--Repeat for Every Window
repeat with x from 1 to windowCount
set tabCount to number of tabs in window x
--Repeat for Every Tab in Current Window
repeat with y from 1 to tabCount
--Get Tab Name & URL
set tabURL to URL of tab y of window x
set docText to docText & ¬
tabURL & ¬
linefeed as string
Thanks for this. But I was looking for would be the front window of the front browser.
Use case: I manage tab sets in KBM (long story) and I sometimes want to make a new set from the current browser window. I've been doing this before by iterating through the tabs with KBM actions, but with Sonoma/KBMv11 it became a little flakey.
You can also write windows there, and a string-preprocessor will munge it back to the underlying windows.at(0) behind the scenes before execution, but ...
a disadvantage of using that cosmetic sugaring is that windows is not, in fact, a JS Array, and using Array indexes on it can confuse you into expecting it to have other Array methods like .map and .filter
(You can derive a real Array of Window object references by writing window(), but once you have called that function to convert from a custom collection object to a standard Array object, you do get access to Array methods like .map, but in exchange you lose access to the window.tabs.url() enchainment across the whole collection. (A real JS Array has no .tabs property or .url() method)
It's feasible, but noticeably slower – multiplying the use of costly Apple Events, especially at scale – to write something like:
windows().tabs().map(tab => tab.url())
which costs one Apple Event per tab, whereas with:
we harvest all of the urls at the price of a single Apple Event.
I'm using Arc as my main browser, is there a solution that works with it? I would like to copy all names and url of all open tabs but the List of URLs in tabs of Front Browser's Front Window macro doesn't work with it
Thanks for your quick reply. I've seen that the Arc Browser is scriptable, i can Open the script dictionary for it, so I thinks a script solution should work, but I'm not able to write such a script; can someone please help me with this?