Skip to content

Instantly share code, notes, and snippets.

@jellea
Last active June 2, 2020 14:29
Show Gist options
  • Select an option

  • Save jellea/95fbff7e8fd820b78f18250d57ace1b9 to your computer and use it in GitHub Desktop.

Select an option

Save jellea/95fbff7e8fd820b78f18250d57ace1b9 to your computer and use it in GitHub Desktop.
Say, a colleague passes you a Figma link, you click it and surprisingly the browser opens, while you have the desktop app installed! You *sigh* and install this script script which adds a question if you want to open web or desktop.

Motivation

Some (web) apps don't give you the choice to open their urls on the web or in their app. This small script allows you to setup up urls to be opened with specific apps and adds a question if web or desktop is desired.

Install

  1. Install Hammerspoon
  2. Install SpoonInstall (unzip and click to install)
  3. Move the contents of appOrWebDialog.lua (question dialog version) or alwaysApp.lua (default to app version) to ~/.hammerspoon/init.lua
  4. Reload Hammerspoon configuration if you already started it.
  5. Set Hammerspoon as default web browser in macOS preferences -> General
defaultBrowser = "org.mozilla.Firefox"
--defaultBrowser = "com.google.Chrome"
hs.loadSpoon("SpoonInstall")
Install=spoon.SpoonInstall
Install:andUse("URLDispatcher",
{
config = {
url_patterns = {
{ "https?://www.figma.com", "com.figma.Desktop" },
{ "https?://www.notion.so", "notion.id" },
},
default_handler = defaultBrowser
},
start = true
}
)
defaultBrowser = "org.mozilla.Firefox"
--defaultBrowser = "com.google.Chrome"
hs.loadSpoon("SpoonInstall")
Install=spoon.SpoonInstall
function openUrl(appBundleID,url,choice)
if choice=="Browser" then
appBundleID = defaultBrowser
end
hs.application.launchOrFocusByBundleID(appBundleID)
hs.urlevent.openURLWithBundle(url, appBundleID)
end
function webOrDesktop (appBundleID,appName,url)
openFn = hs.fnutils.partial(openUrl, appBundleID, url)
hs.dialog.alert(100,100,openFn,"How would you like to open this "..appName.." link?", "", "Desktop App", "Browser")
end
Install:andUse("URLDispatcher",
{
config = {
url_patterns = {
{ "https?://www.figma.com", nil, hs.fnutils.partial(webOrDesktop, "com.figma.Desktop", "Figma") },
{ "https?://www.notion.so", nil, hs.fnutils.partial(webOrDesktop, "notion.id", "Notion")},
},
default_handler = defaultBrowser
},
start = true
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment