How to Execute a Command in a Bash Script and Then Focus The Appearing Window

How to execute a command in a bash script and then focus the appearing window

xdotool is the tool to do so.

The simplest form for your particular task is

xdotool  windowactivate `xdotool search --pid $! `

Window focus adds characters to shell

Turns out this was because of the tmux set-option -g focus-events on setting being set by tmux-sensible plugin. This allows for you to pass on focus events to vim inside of tmux (which I don't do) the issue it seems is that it wasn't being turned off when tmux exited. I simply commented it out, as I don't use features that depend on it.

Cycle through windows of the same application using wmcrtl

I've found a problem in the script, if no window has focus.

May you try the following modified script:

#!/bin/bash
win_class=$1 # 'terminator' # $1

# get list of all windows matching with the class above
win_list=$(wmctrl -x -l | grep -i $win_class | awk '{print $1}' )

# get id of the focused window
active_win_id=$(xprop -root | grep '^_NET_ACTIVE_W' | awk -F'# 0x' '{print $2}')
if [ "$active_win_id" == "0" ]; then
active_win_id=""
fi

# get next window to focus on, removing id active
switch_to=$(echo $win_list | sed s/.*$active_win_id// | awk '{print $1}')

# if the current window is the last in the list ... take the first one
if [ "$switch_to" == '' ];then
switch_to=$(echo $win_list | awk '{print $1}')
fi

# switch to window
wmctrl -i -a $switch_to

How to maintain focus on menu after clicking a menu command

Even if there would a solution for it, sooner or later you will enter a situation in which a numerical or string property is changed via the menu, and then it becomes even impossible to keep the focus on the menu (while the dialog requesting the number or string is on the screen).

The first, simple alternative would be to put the checkable menu items on a toolbar or ribbon (just like Word does with Bold, Italic, Underline, ...). Numerical/string properties can then also be added on the toolbar or ribbon.

A second alternative could be to have a more complete configuration dialog in which the user can change all the configuration items. The configuration dialog can co-exist with the current checkable items, so users simply changing one check and users changing many properties all get a quick way of doing what they want.

You might also pose this question on https://ux.stackexchange.com/ (this sibling site is more oriented towards good user interface practices).



Related Topics



Leave a reply



Submit