epilande / alfred-browser-tabs

🔍 Search browser tabs from Chrome, Arc, Brave, Safari, etc..
MIT License
421 stars 38 forks source link

Edge - Workspaces (or windows) search #48

Open junho85 opened 8 months ago

junho85 commented 8 months ago

The Edge browser has a Workspaces feature. It would be nice to have the ability to search for a workspace and navigate to it. If it's hard to search for just a workspace, I guess a window search would be fine.

example)

list-workspaces.js

#!/usr/bin/env osascript -l JavaScript

function run(args) {
  let browser = args[0];
  if (!Application(browser).running()) {
    return JSON.stringify({
      items: [{
        title: `${browser} is not running`, subtitle: `Press enter to launch ${browser}`,
      },],
    });
  }

  let chrome = Application(browser);
  chrome.includeStandardAdditions = true;

  let items = [];

  for (let window in chrome.windows) {
    let windowId = chrome.windows[window].id();

    items.push({
      title: chrome.windows[window].title(),
      arg: `${windowId}`,
    });
  }

  return JSON.stringify({items});
}

focus-workspace.js

#!/usr/bin/env osascript -l JavaScript

function run(args) {
  ObjC.import("stdlib");
  let browser = $.getenv("browser");
  let query = args[0];
  let [arg1] = query.split(",");
  let windowId = parseInt(arg1);

  focusWindow(browser, windowId);
}

function focusWindow(browserName, windowId) {
  let chrome = Application(browserName);
  chrome.includeStandardAdditions = true;

  let window = chrome.windows.byId(windowId);
  window.visible = true;
  window.index = 1;
  chrome.activate();
}