How to define a global shortcut Ctrl+a 1 with AutoKey which sends the same keystroke Ctrl+a 1 to the window with title 'gnu screen' ? If there is no such titled window it should show a popup message "Couldn't find destination window".
How to define a global shortcut Ctrl+a 1 with AutoKey which sends the same keystroke Ctrl+a 1 to the window with title 'gnu screen' ? If there is no such titled window it should show a popup message "Couldn't find destination window".
Install libnotify-bin which provides notify-send
Create new script:
Setup its hot key as: Ctrl+a
To trigger it: Ctrl+a then 1 (in <1sec)
Debug
Launch X Event Tester in separate terminal window
Check it's window title, mine shows
Event Tester
Modify script to target
Event Tester
window.If
xev
receives the key sequence. Its output should be some thing similar to:Note, I have removed the
if
condition to check active title. The script activates/raises xev window but the check doesn't find the correct title. I got just the notification message.I was thinking along the same lines as "Mostafa Najafiyazdi" and I used his wmctrl function as a base for first script version of the function with some modifications.
This is not autokey specific and as such it's not a python script. I use similar setup to activate, switch and do some stuff on my media-pc (mythtv) with a single remotecontrol button.
Setting windows shortcut/autokey to run these script with combined keys is difficult and ctrl+a is usually globally something different. If you decide to use something ctrl+f7 for the activation key, then calling this script should do what you want.
This requies xdotool and libnotify-bin. This will not change active window to "gnu screen", see commented section to change to the same functionality as with the activate_window_and_send_keys script.
And the script:
My first version required these and is functional (below), but uses extra wrapper and needs window to be active. xdotool version does not require that.
This requires xautomation libnotify-bin and wmctrl
this is ~/bin/activate_window_and_send_keys scipt To do what you want from cmdline, you'd call this with
Remember to chmod u+x on your ~/bin/* scripts
This is ~/bin/sendkey It is simply a wrapper around xte to simplify xte syntax
The first thing that comes to my mind is to break what you want to do in two parts:
Writing a bash function which checks for a window titled whatever you want, for you it would be 'gnu screen', if not found pops up a message saying "Couldn't find destination window!" For this you would first need to install
wmctrl
It is a windows controller which you can use to get windows information including its PID, title, position, size, desktop number, etc. Add the following code in your
.bash_aliases
:You can change how the notification looks like. Just see the manpage for
notify-send
.Define a custom short using your system settings. See here Simple add
find_window "gnu screen"
as the command to run. You define keyboard sequences as you like.EDIT: If the window exists, it will switch to that window! That's what the
else
in theif then else
does.