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.

Revisions

  1. jellea revised this gist Oct 30, 2018. No changes.
  2. jellea revised this gist Oct 30, 2018. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions appOrWebDialog.lua
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    defaultBrowser = "org.mozilla.Firefox"
    --Remove hypens below to set other browser as a default
    --defaultBrowser = "com.google.Chrome"
    --defaultBrowser = "com.apple.Safari"

  3. jellea revised this gist Oct 30, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion appOrWebDialog.lua
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@ defaultBrowser = "org.mozilla.Firefox"
    --defaultBrowser = "com.google.Chrome"
    --defaultBrowser = "com.apple.Safari"

    defaultBrowserName = "Firefox"
    defaultBrowserName = string.match(defaultBrowser, '%a+$')

    hs.loadSpoon("SpoonInstall")
    Install=spoon.SpoonInstall
  4. jellea revised this gist Oct 27, 2018. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion appOrWebDialog.lua
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,6 @@ function openUrl(appBundleID,url,choice)
    -- Workaround: Notion share links can contain the company name, which the desktop app can't open.
    elseif string.find(url, "notion.so/") then
    url = string.gsub(url, "/pitch", "")
    hs.alert.show(url)
    end

    hs.application.launchOrFocusByBundleID(appBundleID)
  5. jellea revised this gist Oct 26, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions appOrWebDialog.lua
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ Install=spoon.SpoonInstall
    function openUrl(appBundleID,url,choice)
    if choice==defaultBrowserName then
    appBundleID = defaultBrowser
    -- Workaround: Notion share links could contain the company name, which the desktop app can't open.
    -- Workaround: Notion share links can contain the company name, which the desktop app can't open.
    elseif string.find(url, "notion.so/") then
    url = string.gsub(url, "/pitch", "")
    hs.alert.show(url)
    @@ -20,7 +20,7 @@ function openUrl(appBundleID,url,choice)
    hs.urlevent.openURLWithBundle(url, appBundleID)
    end

    function webOrDesktop (appBundleID,appName,url)
    function webOrDesktop(appBundleID,appName,url)
    openFn = hs.fnutils.partial(openUrl, appBundleID, url)
    mousePos = hs.mouse.getAbsolutePosition()
    hs.dialog.alert(mousePos.x,mousePos.y,openFn,"How to open this "..appName.." link?", "", appName.." App", defaultBrowserName)
  6. jellea revised this gist Oct 26, 2018. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions appOrWebDialog.lua
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,7 @@ Install=spoon.SpoonInstall
    function openUrl(appBundleID,url,choice)
    if choice==defaultBrowserName then
    appBundleID = defaultBrowser
    -- Workaround: Notion share links could contain the company name, which the desktop app can't open.
    elseif string.find(url, "notion.so/") then
    url = string.gsub(url, "/pitch", "")
    hs.alert.show(url)
  7. jellea revised this gist Oct 26, 2018. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions appOrWebDialog.lua
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,11 @@ Install=spoon.SpoonInstall
    function openUrl(appBundleID,url,choice)
    if choice==defaultBrowserName then
    appBundleID = defaultBrowser
    elseif string.find(url, "notion.so/") then
    url = string.gsub(url, "/pitch", "")
    hs.alert.show(url)
    end

    hs.application.launchOrFocusByBundleID(appBundleID)
    hs.urlevent.openURLWithBundle(url, appBundleID)
    end
  8. jellea revised this gist Oct 25, 2018. No changes.
  9. jellea renamed this gist Oct 25, 2018. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion INSTALL.md → README.md
    Original file line number Diff line number Diff line change
    @@ -4,4 +4,9 @@
    2. Install [SpoonInstall](https://github.com/Hammerspoon/Spoons/raw/master/Spoons/SpoonInstall.spoon.zip) (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
    5. Set Hammerspoon as default web browser in macOS preferences -> General

    # Add more apps
    1. Figure out the App Bundle Identifier. Right click "Show Package Contents" on Application and open `Contents/Info.plist` inside. Find the Bundle Identifier in the plist file.
    2. Add a new line to `url_patterns`: `{ "https?://www.website.com", nil, hs.fnutils.partial(webOrDesktop, "Bundle Identifier here", "App name here") },`
    3. Reload Hammerspoon configuration
  10. jellea revised this gist Oct 25, 2018. 3 changed files with 2 additions and 4 deletions.
    3 changes: 0 additions & 3 deletions README.md → INSTALL.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,3 @@
    # 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](http://www.hammerspoon.org/)
    1 change: 1 addition & 0 deletions alwaysApp.lua
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    defaultBrowser = "org.mozilla.Firefox"
    --defaultBrowser = "com.google.Chrome"
    --defaultBrowser = "com.apple.Safari"

    hs.loadSpoon("SpoonInstall")
    Install=spoon.SpoonInstall
    2 changes: 1 addition & 1 deletion appOrWebDialog.lua
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,9 @@
    defaultBrowser = "org.mozilla.Firefox"
    --defaultBrowser = "com.google.Chrome"
    --defaultBrowser = "com.apple.Safari"

    defaultBrowserName = "Firefox"


    hs.loadSpoon("SpoonInstall")
    Install=spoon.SpoonInstall

  11. jellea revised this gist Oct 25, 2018. 1 changed file with 6 additions and 2 deletions.
    8 changes: 6 additions & 2 deletions appOrWebDialog.lua
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,14 @@
    defaultBrowser = "org.mozilla.Firefox"
    --defaultBrowser = "com.google.Chrome"

    defaultBrowserName = "Firefox"


    hs.loadSpoon("SpoonInstall")
    Install=spoon.SpoonInstall

    function openUrl(appBundleID,url,choice)
    if choice=="Browser" then
    if choice==defaultBrowserName then
    appBundleID = defaultBrowser
    end
    hs.application.launchOrFocusByBundleID(appBundleID)
    @@ -14,7 +17,8 @@ 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")
    mousePos = hs.mouse.getAbsolutePosition()
    hs.dialog.alert(mousePos.x,mousePos.y,openFn,"How to open this "..appName.." link?", "", appName.." App", defaultBrowserName)
    end

    Install:andUse("URLDispatcher",
  12. jellea revised this gist Oct 24, 2018. 1 changed file with 6 additions and 2 deletions.
    8 changes: 6 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,10 @@
    # 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](http://www.hammerspoon.org/)
    2. Install [SpoonInstall](https://github.com/Hammerspoon/Spoons/raw/master/Spoons/SpoonInstall.spoon.zip) (unzip and click to install)
    3. Move the contents of `alwaysApp.lua` or `appOrWebDialog.lua` to `~/.hammerspoon/init.lua`
    4. Set Hammerspoon as default web browser in macOS preferences -> General
    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
  13. jellea created this gist Oct 24, 2018.
    6 changes: 6 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    # Install

    1. Install [Hammerspoon](http://www.hammerspoon.org/)
    2. Install [SpoonInstall](https://github.com/Hammerspoon/Spoons/raw/master/Spoons/SpoonInstall.spoon.zip) (unzip and click to install)
    3. Move the contents of `alwaysApp.lua` or `appOrWebDialog.lua` to `~/.hammerspoon/init.lua`
    4. Set Hammerspoon as default web browser in macOS preferences -> General
    18 changes: 18 additions & 0 deletions alwaysApp.lua
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    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
    }
    )
    31 changes: 31 additions & 0 deletions appOrWebDialog.lua
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    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
    }
    )