nikitabobko / AeroSpace

AeroSpace is an i3-like tiling window manager for macOS
https://nikitabobko.github.io/AeroSpace/guide
MIT License
5.72k stars 90 forks source link

Focus next window of the current application #449

Open Oasixer opened 3 weeks ago

Oasixer commented 3 weeks ago

Hi, I'm wondering what's the easiest way to create a keybind to switch between windows of the same application ie. if I'm in finder, a keybind to focus the next finder window? I realize this is probably scriptable with the existing commands, but I'd rather not reinvent the wheel if this is an existing recipe.

If needed, I can work on scripting this myself, but I figure it's still worth creating an issue for this for the purpose of future searchability so others can copy the result.

Cheers

crates51 commented 3 weeks ago

i also am looking for such an option; my workflow involves two monitors, each monitor with a terminal; 1 left and 1 right

And i am switching between them quite frequently.

At the moment i am using a script created with chatgpt


#!/bin/bash

# Get the focused window information
focused_window=$(/usr/local/bin/aerospace list-windows --focused)

# Extract the window name from the focused window
window_name=$(echo "$focused_window" | awk -F'|' '{print $2}' | xargs)

# Get the ID of the focused window
focused_id=$(echo "$focused_window" | awk '{print $1}')

# Get all windows with the same name
same_name_windows=$(/usr/local/bin/aerospace list-windows --all | grep "$window_name")

# Find the next window ID
next_window_id=""
found_current=false
while read -r line; do
    id=$(echo "$line" | awk '{print $1}')
    if [ "$found_current" = true ]; then
        next_window_id=$id
        break
    fi
    if [ "$id" = "$focused_id" ]; then
        found_current=true
    fi
done <<< "$same_name_windows"

# If we didn't find a next window, wrap around to the first one
if [ -z "$next_window_id" ]; then
    next_window_id=$(echo "$same_name_windows" | awk 'NR==1 {print $1}')
fi

# Focus the next window
/usr/local/bin/aerospace focus --window-id $next_window_id

But feels kinda slow :'(

arglin commented 3 weeks ago

I am using AltTab to do so, this is the only application I found that can switch between windows of a application. I guess it is compatible with Aerospace.

martinengelke commented 3 weeks ago

there is a macOS standard for that in the system settings should be CMD + tilde

Oasixer commented 3 weeks ago

there is a macOS standard for that in the system settings should be CMD + tilde

image

I can't get any of these built-in keybinds to replicate that behavior, could you share the name of that shortcut in the settings?

martinengelke commented 3 weeks ago

it's the "Move focus to next window" (of same application).

Depending where you live (I am from Germany) the standard-key can slightly differ, but you can just choose a new one for that. I just pressed CMD and the key above TAB for that.

Oasixer commented 3 weeks ago

it's the "Move focus to next window" (of same application).

Thanks, this does exactly what I wanted!

crates51 commented 3 weeks ago

Well, i found the setting 'Move focus to next window" and i mapped it to cmd + `

But doesn't really working for me, only inserting inside the terminal `. sadness; oh well, i guess until i make it work i will fallback to my above script.

image

martinengelke commented 2 weeks ago

Try it with a another shortcut first, like cmd ctrl alt Shift a. It was also not running for me with the ` character since I am located in Germany. I changed it to cmd ^ which is the qwertz key next to 1. Often trouble starts with the layout. Maybe you are running another software layout than your hardware shows.

crates51 commented 2 weeks ago

Nope, tried multiple keybinds, none works

Edit: i actually managed to make that work on another MacBook, so i think there's something wrong with mine

arglin commented 2 weeks ago

Nope, tried multiple keybinds, none works

Edit: i actually managed to make that work on another MacBook, so i think there's something wrong with mine

image this only works for window that is active, which means not working for hidden, minimized windows. The only application I found working for windows of same application no matter what status is the window at, is AltTab, not working with apple script, not system shortcut like others mention.