Add a script for counting tabs in Safari
- ID
37c39d4- date
2024-02-23 07:04:52+00:00- author
Alex Chan <alex@alexwlchan.net>- parent
fd70dbb- message
Add a script for counting tabs in Safari- changed files
3 files, 33 additions, 1 deletion
Changed files
macos/.gitattributes (250) → macos/.gitattributes (290)
diff --git a/macos/.gitattributes b/macos/.gitattributes
index 18ce58d..0628d3b 100644
--- a/macos/.gitattributes
+++ b/macos/.gitattributes
@@ -1,4 +1,5 @@
close_tabs linguist-language=JavaScript
+count_tabs linguist-language=JavaScript
get_focus_mode linguist-language=JavaScript
get_live_text linguist-language=Swift
get_photo_sizes linguist-language=Swift
macos/README.md (5528) → macos/README.md (5846)
diff --git a/macos/README.md b/macos/README.md
index 1d304b8..cee628f 100644
--- a/macos/README.md
+++ b/macos/README.md
@@ -25,6 +25,10 @@ scripts = [
"description": "close ephemeral tabs in Safari – basically, anything that can be easily recreated/reopened later."
},
{
+ "name": "count_tabs",
+ "description": "count the number of tabs I have open in Safari."
+ },
+ {
"name": "find_processes_using_secure_input",
"description": "lists any processes using Secure Input, which can block apps like TextExpander"
},
@@ -94,6 +98,15 @@ cog_helpers.create_description_table(folder_name=folder_name, scripts=scripts)
</dd>
<dt>
+ <a href="https://github.com/alexwlchan/scripts/blob/main/macos/count_tabs">
+ <code>count_tabs</code>
+ </a>
+ </dt>
+ <dd>
+ count the number of tabs I have open in Safari.
+ </dd>
+
+ <dt>
<a href="https://github.com/alexwlchan/scripts/blob/main/macos/find_processes_using_secure_input">
<code>find_processes_using_secure_input</code>
</a>
@@ -186,4 +199,4 @@ cog_helpers.create_description_table(folder_name=folder_name, scripts=scripts)
</p>
</dd>
</dl>
-<!-- [[[end]]] (checksum: c269506c592ac8bcea9ed47784bf7616) -->
+<!-- [[[end]]] (checksum: 5190a14c113ded41343a7efe338cccf6) -->
macos/count_tabs (0) → macos/count_tabs (432)
diff --git a/macos/count_tabs b/macos/count_tabs
new file mode 100755
index 0000000..86ac384
--- /dev/null
+++ b/macos/count_tabs
@@ -0,0 +1,18 @@
+#!/usr/bin/env osascript -l JavaScript
+// Counts the number of windows I have open in Safari.
+
+const safari = Application("Safari");
+
+var totalTabs = 0;
+
+const windowCount = safari.windows.length;
+
+for (index = 0; index < safari.windows.length; index++) {
+ totalTabs += safari.windows[index].tabs.length;
+}
+
+if (totalTabs === 1) {
+ console.log('There is 1 tab open.')
+} else {
+ console.log(`There are ${totalTabs} tabs open.`)
+}