7

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.

  • 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 Nov 7 '16 at 7:11
  • You're absolutely right, I forgot about all of that. I'll update the question! – Skeleton Bow Nov 7 '16 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? – user3439894 Nov 7 '16 at 17:35
  • @user3439894 ugh, updated the question again to be clearer. – Skeleton Bow Nov 7 '16 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. – user3439894 Nov 7 '16 at 17:48
3

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.

| improve this answer | |
  • 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 Jun 16 at 16:14
2
+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).

| improve this answer | |
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.

| improve this answer | |
  • Thanks for the answer! The only thing is, I'm looking for an option which avoids this in the first place :) – Skeleton Bow Apr 20 '17 at 8:31

You must log in to answer this question.

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