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

[Feature Request] Hotkey Window #510

Open
jottr opened this issue Sep 15, 2024 · 10 comments
Open

[Feature Request] Hotkey Window #510

jottr opened this issue Sep 15, 2024 · 10 comments

Comments

@jottr
Copy link

jottr commented Sep 15, 2024

It would be very useful to be able to set a keybinding that activates or hides an application window on the currently aktive screen/workspace.
The goal is to achieve something like the drop down terminal Guake, or Dedicated Hotkey Windows in iTerm.

I'm aware of exec-and-forget open <app> and move-node-to-workspace, but haven't found a strategy to achieve the above with these commands.

If it is already possible to achieve this with the current Aerospace feature set, consider this a question.
Otherwise consider this a feature request.

Thanks!

@kjvdven
Copy link

kjvdven commented Sep 24, 2024

@jottr
Copy link
Author

jottr commented Sep 24, 2024

Thanks for trying to help @kjvdven.
That's not what I'm looking for. I only want to open a new application window if the application is not already open.
Otherwise I want to summon the application window to the currently active workspace.
To my (maybe false) understanding, this can only create a new window.

@selflein
Copy link

This might be what you are looking for: #296

@jottr
Copy link
Author

jottr commented Sep 25, 2024

Thanks! This looks like an overly complex solution.
It would be really nice if this feature would be baked into aerospace.
Let's keep this ticket as a feature request then.

@x418
Copy link

x418 commented Oct 26, 2024

In case someone lands here, now that #186 was completed, I extended my own version of the script from #296 (comment) and got XMonad like scratchpad to work that's close to what you are looking for.

#!/usr/bin/env bash

set -euo pipefail

APP_ID="$1"
APP_NAME="$2"
CURRENT_WORKSPACE=$(aerospace list-workspaces --focused)

get_window_id() {
    aerospace list-windows --all --format "%{window-id}%{right-padding} | %{app-name}" |
    grep "$APP_NAME" |
    cut -d' ' -f1 |
    head -n1
}

focus_app() {
    local app_window_id
    app_window_id=$(get_window_id)
    aerospace move-node-to-workspace "$CURRENT_WORKSPACE" --window-id "$app_window_id"
    aerospace focus --window-id "$app_window_id"
}

is_app_closed() {
    ! aerospace list-windows --all --format '%{app-name}' | grep -q "$APP_NAME"
}

move_app_to_scratchpad() {
    local app_window_id
    app_window_id=$(aerospace list-windows --workspace "$CURRENT_WORKSPACE" --format "%{window-id}%{right-padding} | %{app-name}" |
                    grep "$APP_NAME" |
                    cut -d' ' -f1 |
                    head -n1)
    aerospace move-node-to-workspace NSP --window-id "$app_window_id"
}

main() {
    if is_app_closed; then
        open -a "$APP_NAME"
        sleep 0.5
    elif aerospace list-windows --workspace "$CURRENT_WORKSPACE" --format "%{app-bundle-id}" | grep -q "$APP_ID"; then
        move_app_to_scratchpad
    else
        focus_app
    fi
}
main

And I configure it in aerospace.toml like so

cmd-shift-a = 'exec-and-forget /Users/me/.config/scratchpad/nsp.sh com.aptakube.Aptakube Aptakube'
cmd-shift-s = 'exec-and-forget /Users/me/.config/scratchpad/nsp.sh org.whispersystems.signal-desktop Signal'
cmd-shift-e = 'exec-and-forget /Users/me/.config/scratchpad/nsp.sh org.gnu.Emacs Emacs'

I am quite pleased with the results and almost don't miss XMonad.

@jottr
Copy link
Author

jottr commented Oct 26, 2024

Thanks for sharing your solution @x418.
It looks very promising.

@farzadmf
Copy link

farzadmf commented Nov 5, 2024

This is very nice @x418 . I have an issue with this; was wondering if you have a workaround (or maybe you don't face that issue).

I'm using it to "toggle" my WezTerm terminal (right now, I'm doing things in Hammerspoon, which involves adjust the size of the window as well)

With this script, whenever I choose to "show" the window, seems like AeroSpace first tries to fit it in the layout and then realizes I've set it to be floating, but the size stays as it was when AeroSpace tried to fit it in the layout.

@x418
Copy link

x418 commented Nov 7, 2024

This is very nice @x418 . I have an issue with this; was wondering if you have a workaround (or maybe you don't face that issue).

I'm using it to "toggle" my WezTerm terminal (right now, I'm doing things in Hammerspoon, which involves adjust the size of the window as well)

With this script, whenever I choose to "show" the window, seems like AeroSpace first tries to fit it in the layout and then realizes I've set it to be floating, but the size stays as it was when AeroSpace tried to fit it in the layout.

I am afraid I won't be of much help here (never used Hammerspoon). My workflow with Alacritty/WezTerm is quite simple as a one-off terminal (as I don't use any of its fancy features). If you haven't already, perhaps the callbacks maybe of use ?

@farzadmf
Copy link

Thank you for your answer @x418 . Maybe I shouldn't have mentioned Hammerspoon as the issue here is somehow "pure" AeroSpace. I mentioned Hammerspoon only because that's what I'm using now to toggle my terminal, and I was hoping to replace it with the script you provided, but, for some reason, the window size changes when I toggle it.

BUT ... as I was writing this, I gave it another try ... and:

  • Seems like the issue I'm seeing is actually because I've adjusted the window size using Hammerspoon.
  • When I toggle (show) the terminal using the script, adjust the size manually, and use the script again to hide/show, the window appears properly.

I really wish AeroSpace allowed resizing floating windows 🙁

@psiho
Copy link

psiho commented Nov 30, 2024

This is excellent. Saved me from uninstalling Aerospace actually. I only miss the option to add any window to scratchpad. But I don't think it's too much work on a script above to add it. But that's only 10% of my scratchpad use cases and so much more stuff to customize :)
Thanks.

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

6 participants