From 84166ab95417c4376bf24b737eda8ac7212cc13d Mon Sep 17 00:00:00 2001 From: lwouis Date: Sun, 26 Oct 2025 17:04:34 +0100 Subject: [PATCH] feat: new cli command to focus a window using focus order (closes #4610) --- docs/Introduction.md | 5 ++++- src/logic/events/CliEvents.swift | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/Introduction.md b/docs/Introduction.md index 1d109863..534b9377 100644 --- a/docs/Introduction.md +++ b/docs/Introduction.md @@ -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 diff --git a/src/logic/events/CliEvents.swift b/src/logic/events/CliEvents.swift index 54dada2e..d5d3e71b 100644 --- a/src/logic/events/CliEvents.swift +++ b/src/logic/events/CliEvents.swift @@ -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] } }