mjolnirapp / mjolnir

Lightweight automation and productivity app for OS X
5.2k stars 128 forks source link

Force focus a window #536

Closed ianks closed 4 years ago

ianks commented 9 years ago

I am attempting to write a function which will:

  1. Minimize a window
  2. Focus the next visible window

So far I seem to have it so it minimizes the window then attempts to focuse the first visible window(which seems to be indexed at [1]?). Anywho, my issue is that it doesn't actually allow me to minimize the window. My guess is windows are focus-able the way I would like them to be.

Should I be going about this another way, maybe running launchforfocus() on an Application? If so, how can I coerce the userdata object from window.application() into a string?

Thank so much! Having a swell time with Mjolnir :beers:

local grab_closest_window = function()
  local windows = window.visiblewindows()

  if windows then
    return windows[1]
  else
    alert.show("Clean as a whistle.")
    return false
  end
end

local minimizewin = function()
  return function()
    local win = window.focusedwindow()

    if win then
      window.minimize(win)
      window.focus(grab_closest_window())
    else
      alert.show("No focused window.")
      return false
    end
  end
end
thesoftwarephilosopher commented 9 years ago

@ianks Sorry, I'm having a really hard time understanding what you're trying to accomplish. Can you explain it in high-level terms without using any Mjolnir terminology?

ianks commented 9 years ago

I'm essentially just trying to minimize a window, and then have it focus to another window after. That way, I can keep minimizing windows without having to manually refocus windows with my mouse. i.e. repeatedly pressing HYPER j will close all visible windows one by one.

thesoftwarephilosopher commented 9 years ago

@ianks One option is you can just minimize all windows simultaneously, since you have an array of visible windows that you can iterate and act on.

github-actions[bot] commented 4 years ago

Stale issue message