feat: new cli command to focus a window using focus order (closes #4610)

This commit is contained in:
lwouis committed 2025-10-26 17:40:27 +01:00
1 parent a1cfd1de25
commit 84166ab954
2 files changed
+10 -2

No files matched your search

+4 -1
View File
@@ -55,7 +55,10 @@ Change the shortcut keys, switch to a Windows theme and more, using the Preferen
You can run CLI commands directly on the executable inside the .app bundle (e.g. `/Applications/AltTab.app/Contents/MacOS/AltTab`)
* `AltTab --list` will return the list of windows (ID and title) in JSON
* `AltTab --focus=window_id` will focus the window with the specified window ID
* `AltTab --detailed-list` will return the list of windows (lots of info) in JSON
* `AltTab --show=shortcut_index` will show AltTab UI, as if the corresponding shortcut was pressed
* `AltTab --focus=window_id` will focus the window with the specified ID (get it from --list)
* `AltTab --focusUsingLastFocusOrder=focus_order` will focus the window with the specified focus-order (get it from --detailed-list)
For this to work, you need AltTab.app to be running, to keep track of the state of windows, and execute the commands
+6 -1
View File
@@ -78,6 +78,11 @@ class CliServer {
window.focus()
return noOutput
}
if rawValue.hasPrefix("--focusUsingLastFocusOrder="),
let lastFocusOrder = Int(rawValue.dropFirst("--focusUsingLastFocusOrder=".count)), let window = (Windows.list.first { $0.lastFocusOrder == lastFocusOrder }) {
window.focus()
return noOutput
}
if rawValue.hasPrefix("--show="),
let shortcutIndex = Int(rawValue.dropFirst("--show=".count)), (0...3).contains(shortcutIndex) {
App.app.showUi(shortcutIndex)
@@ -122,7 +127,7 @@ class CliClient {
static func detectCommand() -> String? {
let args = CommandLine.arguments
if args.count == 2 && !args[1].starts(with: "--logs=") {
if args[1] == "--list" || args[1] == "--detailed-list" || args[1].hasPrefix("--focus=") || args[1].hasPrefix("--show=") {
if args[1] == "--list" || args[1] == "--detailed-list" || args[1].hasPrefix("--focus=") || args[1].hasPrefix("--focusUsingLastFocusOrder=") || args[1].hasPrefix("--show=") {
return args[1]
}
}