Skip to content

A twist on Brave.jump #6

@danielo515

Description

@danielo515

Hi there,
I hope this message finds you well. Again, I wanted to express my gratitude for your work on hammerspoon. It has been a valuable resource for me and probably many others.

I am writing to share some of my modifications I believe could be interesting for others. I have updated the Brave methods to be configurable for different browsers.

Here is how it looks like

-- browser.lua
return function(browserName)
	local function open()
		hs.application.launchOrFocus(browserName)
	end
	local function jump(url)
		local script = ([[(function() {
      var browser = Application('%s');
      browser.activate();

      for (win of browser.windows()) {
        var tabIndex =
          win.tabs().findIndex(tab => tab.url().match(/%s/));

        if (tabIndex != -1) {
          win.activeTabIndex = (tabIndex + 1);
          win.index = 1;
        }
      }
    })();
  ]]):format(browserName, url)

	-- print(script)
	hs.osascript.javascript(script)
	end
	return { open = open, jump = jump }
end

And this is how it is used:

Chrome = require("browser")("Google Chrome")
Chrome.jump("localhost:3000")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions