I am using Xubuntu desktop, I want to use a keybind (application shortcuts in settings) to activate a command to resize the current window to a predetermined size.
For example: wmctrl -r Firefox -e 1,-1,-1,1000,600resizes any an active firefox window to 1000x600.
The problem is it only works for Firefox, I want to do it to the currently active window (by which I mean the window that has focus).
I know xdotool getwindowfocus getwindowname gives me the current window
but wmctrl -r xdotool getwindowfocus getwindowname -e 1,-1,-1,1000,600 does nothing.
Is there anyway to do this? My guess is maybe I have to use a pipe but I'm not sure.
1 Answer
Code (from posts #6 and #8 in Use wmctrl to unmaximize a window - not toggle:
#!/bin/sh
wmctrl -r :ACTIVE: -b remove,maximized_vert
wmctrl -r :ACTIVE: -b remove,maximized_horz
wmctrl -r :ACTIVE: -e 1,510,21,510,700The first two wmctrl lines are needed for use on active windows which are maximized.
You can choose values for the third line according to your needs.
- Save the code as
resize.shin~/bin. - Open
~/binin Thunar, the file manager, and change the properties ofresize.shby tickingAllow this file to run as a program. - Add the
binfolder to$PATHusingsudo -H mousepad /etc/environmentto insert/home/your_login_name/bin:at the beginning of$PATH. - My path is this:
PATH="/home/dkbose/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"where dkbose is my user name (aka login name) which you should change to yours. Note the:which is used after each path except the last one and the presence of double quotes. - Running
. /etc/environmentmade the change take effect immediately. - You can assign an available keyboard shortcut of your choice to run
resize.sh.