Utility for quickly retrieving windows
Download: https://github.com/adammillerio/Spoons/raw/main/Spoons/WindowCache.spoon.zip
This uses a hs.window.filter to maintain a Least Recently Used cache which can be searched either by window title or application name. This is useful for automations which benefit from quick access to windows.
This was implemented based entirely off of the source of hs_select_window.spoon and split out to be used across other Spoons.
Example Usage (Using SpoonInstall): spoon.SpoonInstall:andUse( "WindowCache", { start = true } )
| Signature | WindowCache.currentWindows |
|---|---|
| Type | Variable |
| Description | Table containing the window cache, ordered by the time it was added to the |
| Source | Source/WindowCache.spoon/init.lua line 57 |
| Signature | WindowCache.logger |
|---|---|
| Type | Variable |
| Description | Logger object used within the Spoon. Can be accessed to set the default log |
| Source | Source/WindowCache.spoon/init.lua line 39 |
| Signature | WindowCache.logLevel |
|---|---|
| Type | Variable |
| Description | WindowCache specific log level override, see hs.logger.setLogLevel for options. |
| Source | Source/WindowCache.spoon/init.lua line 45 |
| Signature | WindowCache.staleWindowCheckInterval |
|---|---|
| Type | Variable |
| Description | Interval in seconds between checks for "stale" windows to be removed from |
| Source | Source/WindowCache.spoon/init.lua line 33 |
| Signature | WindowCache.staleWindowCheckTimer |
|---|---|
| Type | Variable |
| Description | hs.timer periodically running _checkForStaleWindows every staleWindowCheckInterval. |
| Source | Source/WindowCache.spoon/init.lua line 75 |
| Signature | WindowCache.subscribedFunctions |
|---|---|
| Type | Variable |
| Description | Table containing all subscribed instance callbacks for the window filter, used |
| Source | Source/WindowCache.spoon/init.lua line 63 |
| Signature | WindowCache.windowFilter |
|---|---|
| Type | Variable |
| Description | Main hs.window.filter. This is what is used to enumerate and maintain the window |
| Source | Source/WindowCache.spoon/init.lua line 50 |
| Signature | WindowCache.windowsBySpace |
|---|---|
| Type | Variable |
| Description | Table containing per-Space window caches, keyed off of Mission Control Space ID, |
| Source | Source/WindowCache.spoon/init.lua line 69 |
| Signature | WindowCache:findWindowByApp(appName[, spaceID]) |
|---|---|
| Type | Method |
| Description | Find the last opened window by application name. |
| Parameters |
|
| Returns |
|
| Source | Source/WindowCache.spoon/init.lua line 154 |
| Signature | WindowCache:findWindowByTitle(title[, spaceID]) |
|---|---|
| Type | Method |
| Description | Find a window by title. |
| Parameters |
|
| Returns |
|
| Source | Source/WindowCache.spoon/init.lua line 102 |
| Signature | WindowCache:focusWindowByApp(appName[, spaceID]) |
|---|---|
| Type | Method |
| Description | Find the last opened window by application name and focus it. |
| Parameters |
|
| Returns |
|
| Source | Source/WindowCache.spoon/init.lua line 218 |
| Signature | WindowCache:focusWindowByTitle(title[, spaceID]) |
|---|---|
| Type | Method |
| Description | Find a window by title and focus it. |
| Parameters |
|
| Returns |
|
| Source | Source/WindowCache.spoon/init.lua line 136 |
| Signature | WindowCache:getAppNamesForSpace(spaceID) |
|---|---|
| Type | Method |
| Description | Given a spaceID, get a list of all open app names in the space. |
| Parameters |
|
| Returns |
|
| Notes |
|
| Source | Source/WindowCache.spoon/init.lua line 236 |
| Signature | WindowCache:init() |
|---|---|
| Type | Method |
| Description | Spoon initializer method for WindowCache. |
| Parameters |
|
| Returns |
|
| Source | Source/WindowCache.spoon/init.lua line 80 |
| Signature | WindowCache:start() |
|---|---|
| Type | Method |
| Description | Spoon start method for WindowCache. |
| Parameters |
|
| Returns |
|
| Notes |
|
| Source | Source/WindowCache.spoon/init.lua line 393 |
| Signature | WindowCache:stop() |
|---|---|
| Type | Method |
| Description | Spoon stop method for WindowCache. |
| Parameters |
|
| Returns |
|
| Notes |
|
| Source | Source/WindowCache.spoon/init.lua line 438 |
| Signature | WindowCache:waitForWindowByApp(appName, fn[, interval, spaceID]) |
|---|---|
| Type | Method |
| Description | Wait for cached window in appName every interval and run fn when found. |
| Parameters |
|
| Returns |
|
| Source | Source/WindowCache.spoon/init.lua line 199 |