Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add prev_application companion to the new open_application #4011

Open
eugenesvk opened this issue Nov 12, 2024 · 6 comments
Open

Add prev_application companion to the new open_application #4011

eugenesvk opened this issue Nov 12, 2024 · 6 comments

Comments

@eugenesvk
Copy link

eugenesvk commented Nov 12, 2024

There is now an action to open an app open_application, so it would be great to also have a companion action to "undo" it so that you can toggle the same app with one conditional shortcut.
This prev_application action should the bring the previously focused app into focus

@tekezo
Copy link
Member

tekezo commented Nov 17, 2024

Sending Command+Tab is probably the easiest method. Alternatively, you could control it using a shell_command and open command instead of open_application.
Incorporating this into Karabiner-Elements might result in somewhat inconsistent behavior, I think.

@eugenesvk
Copy link
Author

Command+Tab wouldn't work as it would switch to another window of the same app if the 2nd window is the most recent one, then there is this complication that the appswitcher stays opened until you release the from modifier since you're sending to as modifiers, not a command.

Not sure I understand the open alternative, it doesn't seem to have a "previous" option

@tekezo
Copy link
Member

tekezo commented Nov 21, 2024

Not sure I understand the open alternative, it doesn't seem to have a "previous" option

This meant that you would manage the history with a shell script while using the open command to switch to the appropriate application.
It seems that achieving the desired behavior will require meticulous and proper programming.

@eugenesvk
Copy link
Author

I don't see why I'd need to do the error-prone keeping of history:

All I need is to "deactivate" the current app, so change its "Z" order from top to top-1
Or if there is no such "deactivate" api, then I'd just need to activate the "next" app in the Z-list
Neither of these two operations requires even knowing what the top/next apps are, just have access to the listof apps

Karabiner-Elements already has some of that info, it's used in the frontmost app condition?

@tekezo
Copy link
Member

tekezo commented Nov 24, 2024

I see, that's interesting. I had thought the open_application history alone wouldn't be enough, but using the frontmost_application history does seem like it could work. I'll give it a try and see how it works.

@eugenesvk
Copy link
Author

The history might not be enough since there is a chance something else will close an app present in history (or maybe if it's launched hidden it gets to the list of apps, but not to your history of apps that have been at the front).

But from some brief searching it seems macOS is rather deficient here: there is no simple way to get a list of apps in order, e.g., this seems to work, but only within the current space

https://stackoverflow.com/questions/46946860/macos-get-running-apps-ordered-by-most-recently-used-first

So this API would mostly be useful at startup when KE has not seen any history yet, but later on it seems that tracking history which KE already does is indeed the only approach (and given that KE is usually launched at startup, that's a very minor issue)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants