Skip to content

Instantly share code, notes, and snippets.

@mfilej
Created January 16, 2012 10:13
Show Gist options
  • Save mfilej/1620117 to your computer and use it in GitHub Desktop.
Save mfilej/1620117 to your computer and use it in GitHub Desktop.
Make Safari open links from other applications in current space
on open location theURL
tell application "System Events"
if (count of windows of process "Safari") = 0 then tell application "Safari" to make new document
end tell
tell application "Safari" to open location theURL
end open location
<key>CFBundleIdentifier</key>
<string>com.apple.AppleScript.SafariURLHelper</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>SafariURLHelper</string>
<key>CFBundleURLSchemes</key>
<array>
<string>http</string>
<string>https</string>
</array>
</dict>
</array>
<key>NSUIElement</key>
<true/>
@jasondm007
Copy link

@mfilej Thanks for sharing! Since the Mac OS X Hints forum is now read-only, I was wondering if you might know how to address one small thing with this script/app: namely, do you know how to force it to only count windows on the user's active desktop/space? More specifically, this is for people that use more than one monitor, who want Safari to open a new window on their active desktop/space even in cases where a Safari window may be open on their inactive desktop/space (by inactive, I mean visible on another monitor/desktop/space, but not the location of the user's active window).

Under this scenario, all monitors will have their own separate space (Mission Control → Displays have separate spaces). Also, if it's not possible to account for one's active space/desktop when counting windows, then the following locations would also work: (1) cursor/mouse or (2) dock.

Thanks for any help you can lend!!

@mfilej
Copy link
Author

mfilej commented Jul 12, 2019

Hi @jasondm007, unfortunately I don't know how to achieve that. I also stopped using the script because it was a bit unreliable.

@jasondm007
Copy link

Hi @mfilej - Thanks for getting back to me.

No problem. I'll keep poking around, and let you know if I find a better solution. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment