5

It is possible to bind custom key for switch to specific application?

For example:
super+1 switches to the chrome window (not a first in windows list).
super+2 switches to the nautilus window

Or at least:
super+1 switches to first window
super+2 switches to second window

2

This would take a bit of work but you could do this with scripts and keybindings.

There is a tool called xdotool and it lets you simulate keyboard presses. You can bind your keyboard keys to run scripts that utilize this tool.

Using whatever language you prefer to pipe terminal commands, you can find specific process IDs with ps aux | grep "process here"

Using xdotool search --pid "process ID here" you will get back multiple window IDs for a single application. I don't know how to sort through them to find the correct one, so what you could do is have your script, iterate thought the found IDs into

xdotool windowactivate "window ID here" which will bring up your window.

For example, my 1 key will be binded to run a script that find the process ID for "filezilla". Then it will find the window IDs with xdotool, take those IDs and then pass them through xdotool to pull up the window. The 2 key, could be "google-chrome"

  • 1
    It's windowactivate not windowsactivate. – Hemm Mar 4 '14 at 18:52
0

I've put together what Mr.Lee suggested and created this script:

#!/bin/bash                                                                     

APP=$1                                                                          
if [ -z "$APP" ]; then                                                          
  echo Usage: $0 EXECUTABLE_NAME                                                
  exit 1                                                                        
fi                                                                              

PID=$(pgrep -f $APP | head -n 1)                                                
if [ -z "$PID" ]; then                                                          
  echo $APP executable not found                                                
  exit 2                                                                        
fi                                                                              

for WINDOW_ID in $(xdotool search --pid $PID); do                               
  xdotool windowactivate $WINDOW_ID                                             
done                                                                            

notify-send "Switched to $APP (PID=$PID)" 

It basically ignores the possibility of any error, but works for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.