johnste / finicky

A macOS app for customizing which browser to start
MIT License
3.71k stars 137 forks source link

Open YouTube links from Slack in specific browser #311

Closed hapimp closed 1 year ago

hapimp commented 1 year ago

I've managed to get Finicky to open all links I click in Slack in Firefox, but I only want it to happen with YouTube links and I don't understand the syntax well enough to do this. This is what I have now:

// Generated by Finicky Kickstart 
// Save as ~/.finicky.js

module.exports = {
  defaultBrowser: "Google Chrome",      
  handlers: [
    {
      // Open any link clicked in Slack in Safari
      match: ({ opener }) =>
        opener.bundleId === "com.tinyspeck.slackmacgap",
      browser: "Firefox"
    },
    {
      match: /^https?:\/\/youtube\.com\/.*$/,
      browser: "Firefox"
    }
  ]
}

Any ideas to how I can do this?

thobe commented 1 year ago

In order to get that done you will want to specify that your match expresses a predicate on both the opener and the url. I believe that would look something like this:

module.exports = {
  defaultBrowser: "Google Chrome",      
  handlers: [
    {
      // Open youtube link clicked in Slack in Firefox
      match: ({ url, opener }) =>
        opener.bundleId === "com.tinyspeck.slackmacgap" && (url.host === "youtube.com" || url.host === "youtu.be"),
      browser: "Firefox"
    },
  ]
}
hapimp commented 1 year ago

Thank you very much for pointing me in the right direction @thobe ! I was not able to make your code work, but I ended up finding another example in the wiki going with what you wrote. By modifying it a bit, everything now seems to work.

My code:

module.exports = {
  defaultBrowser: "Google Chrome",      
  handlers: [
    {
      // Open youtube link clicked in Slack in Firefox
      match: ({ opener, url }) =>
        opener.bundleId === "com.tinyspeck.slackmacgap" && url.host.includes("youtube.com") || url.host.includes("youtu.be"),
      browser: "Firefox"
    }
  ]
}