Calendar Tab AppleScript Shortcut

Description of what you are sharing

My most used BTT button opens Google Calendar up to this week's view. Inevitably, I kept having 4-5 calendar tabs open because if I wasn't on my calendar tab it was easier to quickly open a new one than to find the right one. I got sick of that, so I figured an Apple Script would be the easiest way to:

  1. Search to see if there's already a calendar tab open, open that tab, and switch to this week's view.
  2. If there's not, open a new tab.
  3. Set the new tab to this week's view.

So, here's my script:

tell application "Google Chrome"
	repeat with w in windows
		set i to 1
		repeat with t in tabs of w
			if URL of t starts with "https://calendar.google" then
				set active tab index of w to i
				set index of w to 1
				if URL of t is not "https://calendar.google.com/calendar/u/1/r/week" then
					set URL of t to "https://calendar.google.com/calendar/u/1/r/week"
				end if
				return
			end if
			set i to i + 1
		end repeat
	end repeat
	open location "https://calendar.google.com/calendar/u/1/r/week"
end tell

Note: The "u/1" in the URL string makes sure it goes to the right user profile that I have signed into Google on my machine. Adjust it for your own setup.

The code is also here: Calendar Shortcut Apple Script - for use with BetterTouchTool ยท GitHub

I love how we tend to find geeky solutions to simple issues :grin:
I'm sure I'd do the same if I knew code.
For the time being, as a Firefox user, I have an extension take care of duplicate tabs. But that's not BTT related, of couse.

Anyway, thank you for this! Could serve as an inspiration to write another script.