Follow these instructions to create a 'BrowserHereHelper' (or name it whatever you want for easy Spotlight'ing) application that can:
- Activate a browser window, if it's open in the current Space already;
- create a new window, if there's none in the current Space (instead of switching to another Space!);
- open links from other applications in the current Space (again, instead of switching to another Space to open the link you clicked. 🙄)
For obvious reasons, this is only useful if your default setting in System Preferences is "When switching to an application, switch to a Space with open windows for the application." This script is intended to exempt certain apps, like browsers, from that otherwise-wonderful behaviour.
Follow these instructions to create an AppleScript App that can be used to open URLs:
-
Open Script Editor (in
/Applications/Utilities
). -
Copy-paste the below script into a new document.
-
Save the document as an 'Application'
Warning Do not attempt to run it yet; complete the rest of the steps first. (If you have, you may need to delete the package entirely, and start over with a new Script Editor document.)
-
Use the Terminal to edit the
Contents/Info.plist
file inside your newly-created application-bundle (e.g. If the app is at~/Applications/BrowserHereHelper.app
then theInfo.plist
will be at~/Applications/BrowserHereHelper.app/Contents/Info.plist
) with an editor of your choice;$ nano "/Applications/BrowserHereHelper.app/Contents/Info.plist"
Warning Do not use the Finder to 'Show Package Contents', as that can cause the following code-signing steps to fail.
-
Add a
CFBundleURLTypes
section to thatInfo.plist
, indicating it can handle HTTP URLs (seeInfo.plist
below for an example). -
Re-sign the generated application to pick up the additional
Info.plist
entry by running a command like this one in the Terminal:$ codesign -fs - --preserve-metadata=entitlements /Applications/BrowserHereHelper.app /Applications/BrowserHereHelper.app: replacing existing signature
-
Open System Preferences > Security & Privacy > Accessibility, and drag your newly-signed app into the 'allow the apps below to control your computer' area, making sure it ends up checked:
-
Test your application from the command line using
open -a ~/Applications/MyApp.app http://www.example.com
-
Use the application however you like — my favourites are setting it as the
defaultbrowser
(although in that case, make sure to modify the script below to setpreferredBrowser
to the value of your choice!), using it via Spotlight ⌘␣ (naming itFirefoxHereHelper
means I didn't even have to change my muscle-memory 😅), or tying into it with Choosy.app.
AppleScripts, assistive-access permissions, and so on seem super fragile in my experience.
Expand the below toggle for some of my tips for fixing issues, some cargo-culted, some discovered through trial-and-error:
If attempting to open a url with `open` has absolutely no effect whatsoever, or if you run into this error:
executable_is_endpoint_security_client
failed for pathfile:///Applications/BrowserHereHelper.app/Contents/MacOS/appletInfo.plist
(plist or signature have been modified)… you may have forgotten to use 'export' mode in Script Editor and/or forgotten to switch to 'Don't Code Sign.' Delete the app entirely and start from scratch.
If you run into any of these errors,
- System Events got an error: BrowserHereHelper is not allowed assistive access. (-25211)
- Not authorized to send Apple events to System Events. (-1743)
… you may have munged up the
Info.plist
permissions, or macOS may just have cached some values incorrectly. First, check yourInfo.plist
; and if that fails, you may be able to 'kick' the system back into giving you access by some combination of the following steps:-
Delete, and then manually re-add,
BrowserHereHelper.app
to the Privacy > Accessibility pane, exactly as in step 7 above -
Run some:tm: combination of the following commands in the Terminal:
tccutil reset Accessibility tccutil reset AppleEvents tccutil reset SystemPolicyAllFiles tccutil reset SystemPolicySysAdminFiles
-
Delete the
BrowserHereHelper.app
entirely, start from scratch; or even -
Delete the app entirely, start from scratch, and use a new name and package identifier. Oof.