For years, I have F2 and F3 in vim set to move the current tab left and right respectively. I wanted to do the same in Safari. I found a way to do it with AppleScript.

Save this as a Quick Action “Move Current Safari Tab Left.workflow” as a Run AppleScript action:

--Move left
tell application "Safari"
	set currentTabIndex to index of current tab of front window
	set totalTabs to count of tabs of front window
	-- Ensure there is a previous tab to swap with
	if currentTabIndex > 1 then
		set previousTabIndex to currentTabIndex - 1
		-- Swap the tabs
		tell front window
			set currentTab to tab currentTabIndex
			set previousTab to tab previousTabIndex
			move previousTab to after currentTab
		end tell
	end if
end tell

Save this as a Quick Action “Move Current Safari Tab Right.workflow” as a `Run AppleScript action:

--Move right
tell application "Safari"
ve
	set currentTabIndex to index of current tab of front window
	set totalTabs to count of tabs of front window
	-- Ensure there is a next tab to swap with
	if currentTabIndex < totalTabs then
		set nextTabIndex to currentTabIndex + 1
		-- Swap the tabs
		tell front window
			set currentTab to tab currentTabIndex
			set nextTab to tab nextTabIndex
			move nextTab to before currentTab
		end tell
	end if
end tell

The workflows accepts no input in Safari.app.

Then, under the Settings.app > Keyboard > Keyboard Shortcuts > App Shortcuts, assign these 2 to Safari.app:

  • “Move Current Safari Tab Left” to cmd+F2
  • “Move Current Safari Tab Right” to cmd+F3

(I didn’t use F2 and F3 because I have assign them to do other things in Safari)

Couple them with assigning these to All Applications too:

  • “Select Previous Tab” to ctrl-h
  • “Select Next Tab” to ctrl-l

These 4 keyboard shortcuts make moving around and re-ordering tabs in Safari so much easier.