MacOS – Keyboard shortcut to move tabs left or right

automationhigh sierrakeyboardmacossafari

Is there a Safari keyboard shortcut to move a tab?

If not, how can I make one?

I wouldn't even know how to write an AppleScript for this, the only method I see of moving tabs is to drag them.

Best Answer

Here are two AppleScripts for moving tabs one position right or left. The AppleScript gets the current tab index, checks if it can be moved, then moves it and ensures it's still active. This does refresh the page though but this appears to be a limitation of the AppleScript since it uses the Standard Suite's move.

  • Move tab one to the right

    tell application "Safari" to tell front window
        set currentindex to index of current tab
        if currentindex is equal to number of tabs then return
        move tab currentindex to after tab (currentindex + 1)
        set current tab to tab (currentindex + 1)
    end tell
    
  • Move tab one to the left

    tell application "Safari Technology Preview" to tell front window
        set currentindex to index of current tab
        if currentindex is 1 then return
        move tab currentindex to before tab (currentindex - 1)
        set current tab to tab (currentindex - 1)
    end tell
    

You can assign keyboard shortcuts to these by creating a service to run these scripts and assigning a shortcut to the service, or with a third-party app.