16

I have multiple Safari windows for tab organization. I usually have multiple tabs in each window.

When I click on a link from an app other than Safari, it opens the link in a new tab in Safari, as Safari is my default browser.

The problem is that it often opens in a Safari window that is currently minimized or that I am currently not using. So it doesn't open the link in my main, active, current window (basically the one I have used last). Instead, it chooses its own "default window" to open links in, which may be a window I'm not even using.

However, I would like these links to always open in the window that I used last, and not in a window that I'm not using. Is it possible to make links always open in the last active window you used, or at least set the "default" window which will open new links?

I am currently running macOS Sierra 10.12.1, with the default Safari version that comes with it.

13
  • You will need to provide more info in order for the community to help you. As your question currently stands, we have no idea whether you're talking about Safari in an iOS device or on a Mac? Also, what OS are you using? That is, if it's macOS, is it macOS Sierra, El Capitan, etc? If it's an iPhone, are you running iOS 10, iOS 9, something else? Regardless, please provide the exact version. And, if it's a Mac, also provide the exact version of Safari you're running.
    – Monomeeth
    Commented Nov 7, 2016 at 7:11
  • You're absolutely right, I forgot about all of that. I'll update the question!
    – Oion Akif
    Commented Nov 7, 2016 at 17:08
  • You said "this is the one when all the other windows are closed, and is in the foreground", did you mean to say minimized not closed? Commented Nov 7, 2016 at 17:35
  • @user3439894 ugh, updated the question again to be clearer.
    – Oion Akif
    Commented Nov 7, 2016 at 17:43
  • I believe the answer is going to be no, it is not possible to set the "default" window which will open new links in when initialed by another app. Commented Nov 7, 2016 at 17:48

4 Answers 4

8

This can be done with an AppleScript app which opens the link in Safari and making this app the default browser.

I've found two versions while testing: either open in new windows or in new tabs if there's already a window in the current space.

  • Open Script Editor.app (or even better Script Debugger)

  • If you want links to open in a new window use this

    on open location theURL    
        tell application "Safari"  
            make new document with properties {URL:theURL}  
            activate  
        end tell  
    end open location  
  • If you want links to open in a new tab (if a window is available in the current space) use this:
    on open location theURL  
        tell application "System Events"  
            tell process "Safari"  
                try  
                    set frontWinName to name of window 1 
                on error  
                    my openNewWindow(theURL)  
                    return  
                end try  
            end tell  
        end tell  

        tell application "Safari"  
            try  
                tell (first window whose name is frontWinName and miniaturized is false)  
                    set current tab to make new tab with properties {URL:theURL}  
                    activate  
                end tell  
            on error  
                my openNewWindow(theURL)  
            end try  
        end tell  
    end open location  


    on openNewWindow(theURL)  
        tell application "Safari"  
            make new document with properties {URL:theURL}  
            activate  
        end tell  
    end openNewWindow  
  • Save as app

  • If you don't want the app shown in dock

    • Right click the app, go into the package and find Info.plist

    • Add this in Info.plist

        <key>LSUIElement</key>  
        <true/>
    
  • Set the app as default browser (I used RCDefaultApp).

If you want to see how annoying the default macOS link behaviour is I suggest switching back to Safari as default browser after some hours ...

I'm still on 10.14.6 and don't know possible restrictions in Catalina.

2
  • This works! And it is the only solution I have seen anywhere on the web. To set the default browser, I used SwiftDefaultApps (github.com/Lord-Kamina/SwiftDefaultApps/releases/tag/v2.0.1) since RCDefaultApp does not work with Catalina.I did not edit the Info.plist and the app did not show in dock regardless.
    – phatmann
    Commented Jun 16, 2020 at 16:14
  • Of note, on more recent versions of macOS this also requires Automation permissions in System Preferences/Settings > Security & Privacy. I wasn't able to get that to trigger without some combination of editing the script to call System Events on launch (to test), re-generating the app via Export > App from Script Editor and launched it manually, and launching the app manually to trigger this. A more systematic approach to getting the proper permissions would be a welcome update to this solution.
    – jrk
    Commented Oct 30, 2022 at 20:53
4
+50

As a developer I researched the possibility of extensions being able to achieve what you want by always opening a new window when clicking a link contained outside of Safari itself. I'm sorry to say I don't think this approach is going to be possible.

Unfortunately, Safari does not give extensions a way to determine the origin of a new tab/window. What I mean by this is that a new tab can be created because the user clicks a link in an email, command-clicks a link in Safari, opens a Safari bookmark while holding down Command, clicks a link within a PDF document, or any one of several other actions that will open a page in a new tab. Regardless of the method, Safari does not provide how the window was opened to a Safari extension.

Since all these events look the same, no extension can force links from outside Safari to open in new windows without also affecting links opened in other ways (including while browsing within Safari).

0

Although it doesn't natively open in your desired window, you can always grab the tab and reposition it to another safari window directly after it has opened.

Not sure if this helps or not, just a suggestion.

2
  • 1
    Thanks for the answer! The only thing is, I'm looking for an option which avoids this in the first place :)
    – Oion Akif
    Commented Apr 20, 2017 at 8:31
  • @OionAkif did you find a way to do it ? it is really annoying when you have more than one monitor and, in each, more than one browser windows (each with active multiple tabs).
    – McLan
    Commented Oct 16, 2023 at 9:32
0

I found one thing that could be helpful. I use Apple Mail in full screen mode usually on the display designated as the main display. When I click a link from Mail in full screen mode, the link will open in a Safari window running on the other display. If Mail is not running in full screen mode, the link will open in the Safari window on the same display that Mail is running on, and it will leave the Safari window on the second display alone. Having found this out, if I know I will be clicking a lot of links from Mail, I will just take Mail out of full screen mode. I think the behavior we are seeing is intentional.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .