1

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,600 resizes 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.

DK Bose
  • 42,548
  • 23
  • 127
  • 221

1 Answers1

0

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,700

The 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.sh in ~/bin.
  • Open ~/bin in Thunar, the file manager, and change the properties of resize.sh by ticking Allow this file to run as a program.
  • Add the bin folder to $PATH using sudo -H mousepad /etc/environment to 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/environment made the change take effect immediately.
  • You can assign an available keyboard shortcut of your choice to run resize.sh.
DK Bose
  • 42,548
  • 23
  • 127
  • 221
  • Thanks, but I'm confused on the second part. After adding resize.sh to /bin/, what do I do?

    etc/environment starts with: PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/us...

    where do I add /home/my_login_name/bin?

    – Hitomi86 Apr 13 '18 at 09:39
  • Note that I suggest creating a bin folder in your /home directory (that's what ~/bin means), not in the system itself! It's usually not advisable to add stuff to /bin which is very different than ~/bin. Please see the edited answer for the PATH stuff. All the best. – DK Bose Apr 13 '18 at 09:56
  • Code changed to deal with maximized windows. – DK Bose Apr 13 '18 at 11:21
  • Thanks, I did the following and it makes more sense. but I get the following error when I tried to run it: bash: /home/shamthosh/bin/resize.sh: Permission denied . If I run as sudo, then I get: sudo: resize.sh: command not found. – Hitomi86 Apr 13 '18 at 21:57
  • You need to make the script executable. Answer has been edited. No need for sudo. – DK Bose Apr 14 '18 at 01:10