Open links posted to Slack in a specific browser

433 views
Skip to first unread message

Allan DeBono

unread,
Oct 24, 2021, 12:59:01 PM10/24/21
to Hammerspoon
Hello all:

I would like to open a link posted in Slack with my work browser (Firefox).

This is what I have in my .lua based on Diego Zamboni's tutorial


spoon.SpoonInstall.use_syncinstall = true

Install=spoon.SpoonInstall

function appID(app)
  return hs.application.infoForBundlePath(app)['CFBundleIdentifier']
end

FirefoxBrowser = appID('/Applications/Firefox.app')
SafariBrowser = appID('/Applications/Safari.app')
Slack = appID('/Applications/Slack.app')
Zoom = appID('/Applications/Zoom.us.app')


DefaultBrowser = SafariBrowser
WorkBrowser = FirefoxBrowser

Install:andUse("URLDispatcher",
               {
                 config = {
                   url_patterns = {
                     { "https://gmail.com",        WorkBrowser },
                     { "https://drive.google.com",        WorkBrowser },
                     { "https://calendar.google.com",        WorkBrowser },
                     { "https://%zoom.us%",        Zoom }
                   },                
                   default_handler = SafariBrowser
                 },
                 start = true,
                 -- Enable debug logging if you get unexpected behavior
                 -- loglevel = 'debug'
               }

I do not know how to make the slack redir urls command work. Have you made this work? Do you have an example you are willing to share with the correct syntax? 

Thank you,
Allan

Diego Zamboni

unread,
Oct 24, 2021, 3:14:23 PM10/24/21
to Allan DeBono, Hammerspoon
Hi Allan,

Your config looks correct to me - those patterns when clicked should open in Firefox. The decode_slack_redir_urls parameter defaults to true, so it should handle the URLs as created by Slack correctly.

If this doesn't work, could you uncomment the `loglevel` parameter (set it to "debug") and post the output you get in the Hammerspoon console when clicking a URL?

--Diego


--
You received this message because you are subscribed to the Google Groups "Hammerspoon" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hammerspoon...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/hammerspoon/9179693f-20df-4cce-ad74-9a8acab346a9n%40googlegroups.com.

Allan DeBono

unread,
Oct 24, 2021, 6:26:51 PM10/24/21
to Hammerspoon

Hi Diego:

Thank you for your response. I learned most of what I know about Hammerspoon from your documentation and youtube channel.
You are correct. The links as shown above all open in Firefox every time.

The remaining problem is that I am still not seeing where and how to add 
URLDispatcher.decode_slack_redir_urls = true
without invoking an error.  If you have any pointers as to where to add the code in the lua would be appreciated.

Thank you — Keep up all of your great work.
Allan

Diego Zamboni

unread,
Oct 25, 2021, 10:27:51 AM10/25/21
to Allan DeBono, Hammerspoon
Hi Allan,

Glad to know you've found my stuff useful!

As I said, the decode_slack_redir_urls parameter is set to true by default, so you don't have to set it. If you wanted to make it explicit, you can do it in the "config" section of the SpoonInstall::andUse statement, like this:

Install:andUse("URLDispatcher",
               {
                 config = {
                   url_patterns = {
                     { "https://gmail.com",        WorkBrowser },
                     { "https://drive.google.com",        WorkBrowser },
                     { "https://calendar.google.com",        WorkBrowser },
                     { "https://%zoom.us%",        Zoom }
                   },                
                   default_handler = SafariBrowser,
                   decode_slack_redir_urls = true,
                 },
                 start = true,
                 -- Enable debug logging if you get unexpected behavior
                 -- loglevel = 'debug'
               }

You can also set it directly after the module has been loaded (or from the console), as follows:

spoon.URLDispatcher.decode_slack_redir_urls = true

--Diego

Allan DeBono

unread,
Oct 28, 2021, 12:06:05 PM10/28/21
to Diego Zamboni, Allan DeBono, Hammerspoon
Thanks for your help Diego — I was not able to get links from Slack to open with Firefox. But I used ‘finicky’ app to perform the behavior.
Great work with all of your knowledge sharing. You made my work flows better!

Thank you

Diego Zamboni

unread,
Nov 3, 2021, 7:14:17 AM11/3/21
to Allan DeBono, Allan DeBono, Hammerspoon
Hi Allan,

Ah, I think I finally understood what you needed: you want links to open in Firefox only when opened from Slack, correct?

Unfortunately this functionality does not exist in URLDispatcher yet, but it should be very easy to add - there is already app-specific URL transformation rules. I'll see if I can work on this in the next few days.

--Diego

Yossi Keshet

unread,
Jul 1, 2024, 7:53:48 AM7/1/24
to Hammerspoon
Hi Diego
Was this option added?
Thanks
Yossi

Diego Zamboni

unread,
Jul 2, 2024, 4:15:34 AM7/2/24
to Yossi Keshet, Hammerspoon
Hi Yossi,

Sorry, I've not had a chance to work on URLDispatcher in a while :(

--Diego


Reply all
Reply to author
Forward
0 new messages