Skip to content

Instantly share code, notes, and snippets.

@AFutureD
Last active April 17, 2025 11:12
Show Gist options
  • Save AFutureD/7b702d5ef43658d70606d0d9b054d981 to your computer and use it in GitHub Desktop.
Save AFutureD/7b702d5ef43658d70606d0d9b054d981 to your computer and use it in GitHub Desktop.
tell application "System Events"
tell process "Safari"
set frontmost to true
-- Reference Safari window
set safariWindow to front window
delay 0.5
set sidebarVisible to false
try
set sidebarVisible to exists (group 1 of splitter group 1 of window 1)
end try
if not sidebarVisible then
-- Use the keyboard shortcut to show the sidebar (Command+Shift+L)
keystroke "l" using {command down, shift down}
delay 0.5 -- Wait for the sidebar to appear
end if
if exists button 1 of group 1 of splitter group 1 of window 1 then
set backButton to button 1 of group 1 of splitter group 1 of window 1
if description of backButton contains "Back" then
click backButton
end if
end if
set sidebarGroup to outline 1 of scroll area 1 of group 1 of splitter group 1 of window 1
tell sidebarGroup to perform action "AXShowMenu"
--- set tabGroup to the first row of sidebarGroup whose description of UI element 1 contains "Tab Group"
--- log tabGroup
set sidebarMenu to menu 1 of outline 1 of scroll area 1 of group 1 of splitter group 1 of window 1
if exists menu item "Show Tabs in Sidebar" of sidebarMenu then
set target to menu item "Show Tabs in Sidebar" of sidebarMenu
tell target to perform action "AXPress"
else
tell sidebarMenu to perform action "AXCancel"
end if
end tell
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment