1#!/usr/bin/env osascript -l JavaScript
2// A script to list all my open Safari tabs.
4safari = Application("Safari");
6// Generates all the window/tab/URLs in Safari.
8// This runs in reverse window/tab index order: that is, windows are returned
9// bottom to top, and tabs from right to left.
10function* tabGenerator() {
11 window_count = safari.windows.length;
13 for (window_index = window_count - 1; window_index >= 0; window_index--) {
14 window = safari.windows[window_index];
16 tab_count = window.tabs.length;
18 for (tab_index = tab_count - 1; tab_index >= 0; tab_index--) {
19 tab = window.tabs[tab_index];
25// Print the list of tabs to stdout.
26// See https://apple.stackexchange.com/a/278395/14295
27Array.from(tabGenerator()).join('\n');