Skip to content

Instantly share code, notes, and snippets.

@0xBADC0FFEE
Forked from mfilej/Info.plist
Last active May 20, 2020 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0xBADC0FFEE/19c57eac0b5cb66e0da5ed02e3ada81f to your computer and use it in GitHub Desktop.
Save 0xBADC0FFEE/19c57eac0b5cb66e0da5ed02e3ada81f to your computer and use it in GitHub Desktop.
Make Safari open links from other applications in current space

http://hints.macworld.com/article.php?story=20091013114424722

As a prerequisite, you'll need to install the RCDefaultApp preference pane https://github.com/Lord-Kamina/SwiftDefaultApps

Open AppleScript Editor and paste in content of _Script.scpt

Save the document using file format Application, and select the Stay Open checkbox. Name it SafariURLHelper. I have an Applications folder in my home directory in which I saved it. Using the Finder, navigate to where you saved SafariURLHelper, then Control-click its icon and select Show Package Contents from the contextual menu. Inside the Contents folder, find Info.plist, and open it in a text editor.

Add content of Info.plist to the bottom of the file, just before the closing and tags

If you had already run the script without this improvement, quit it using "Activity Monitor.app". You can also update the saved Helper app in Script Editor without the need to edit the Info.plist again - our changes are preserved.

on open location theURL
tell application "System Events"
if (count of windows of process "Safari") = 0 then
tell application "Safari" to make new document
tell application "Safari" to set the URL of the front document to theURL
else
tell application "Safari" to open location theURL
end if
end tell
tell application "Safari" to activate
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/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment