Always, 100% of the time, open tabs to the right of the current tab in Safari for macOS

Here's how you can fix the chronic pain in the neck New Tab behaviour in Safari for macOS, where there's no way at all for users to decide the position their new tabs should open at.

For new blank tabs
  1. Download Keyboard Cowboy [open source]

  2. Install and launch it

    Once opened, in the leftmost panel…

  3. Under Configuration, leave it at Default Configuration

  4. Under Groups, click the barely visible Add Group button

  5. In the window that opens, set the name to Safari, then in the Application drop-down menu, select Safari, and finally click Save

  6. Make sure the Safari group is selected

    In the middle panel…

  7. Under Workflows, click the barely visible Add Workflow button

    In the rightmost panel…

  8. Set the workflow name to e.g. New tab

  9. Under Add Trigger, click the Keyboard Shortcut button

  10. Use command-T as the keyboard shortcut

  11. Click the New Command button and then in the popup menu, select Scripting and then New AppleScript

  12. Set name of the script to e.g. New tab script

  13. Click the Script goes here… field and paste the following
    tell application "Safari"
      tell front window
      set _new to make new tab at after (get current tab)
      set _url to "x-safari-https://"    # this url makes sure the 'New tabs/windows open with' settings are applied
      set URL of _new to _url
      repeat until URL of _new is not _url    # wait until the tab gets a real url, or else the location bar won't be focused when switching to the new tab
      delay
      end repeat		
        set current tab to _new
      end tell
    end tell
    
    

  14. Open Safari and test the keyboard shortcut

    Optionally also…

  15. In the leftmost panel in Keyboard Cowboy go into every group and disable the factory-installed workflows, since some of them have keyboard shortcuts as triggers that you might not like

  16. To get rid of the dock icon, click the icon and then in the open Keyboard Cowboy window, press command-W or click the red close button in the top-left corner (don't press command-Q, or the background process too gets terminated)

  17. To make Keyboard Cowboy start automatically when you log in, click the menu bar icon and select Open at Login

  18. In case you don't fancy the menu bar icon, you can hold the command key and drag the icon as far as possible to the right so it gets out of sight

  19. In Safari, right-click the toolbar, choose Customize Toolbar… and drag the + icon out of the toolbar

Should you actually want to open a tab at the end of the tab bar, you can always press option-command-T



For new tabs opened from links

Open Terminal and run the following commands:
defaults write com.apple.safari WBSNewTabPositionPreferenceKey -int 0

defaults write com.apple.safari WBSNewTabPositionAppliesToSpawnedTabsPreferenceKey -int 1

Then restart Safari (in case you haven't configured Safari to automatically reopen previous windows, click Reopen All Windows from Last Session under History in the menu bar)