DEV Community

Cover image for How I open and resize all my applications with just a keyboard shortcut

How I open and resize all my applications with just a keyboard shortcut

Ricardo Borges on July 13, 2020

Every morning I have to open, resize and reposition all applications I need to work, so I thought: What if I only had to press a keyboard shortcut ...
Collapse
 
thiagoa profile image
Thiago Araújo Silva • Edited

Cool script! On my end, I use devilspie2 to monitor new windows and do whatever I want with them. That along with Gnome's automatic shortcuts for favorite applications (Win+1, Win+2, ..., until Win+9) makes the process lazy for me because I just trigger the shortcut to open the app and its window appears exactly where I want. Here is my configuration file in Lua.

I imagine your script might have a few edge cases to deal with. For instance, I think you should match by WM_CLASS instead of window title. If there's an unrelated window with "google" in its title and it appears before Google Chrome, your script will probably resize the wrong window. For that, you should probably use wmctrl -xl, which will also print out the application's WM_CLASS, and then parse the output.

I even use this trick in my Lua config file to figure out how many Chrome windows are open and only act on the window if it's the first one.

Collapse
 
twright profile image
Thomas Wright • Edited

On the one hand I can see many uses of such a script. On the other hand, I cannot help seeing a shorter alternative article:
"Every morning I have to open, resize and and reposition all applications I need to work, so I thought: What if I used suspend/hibernate?"

This alternative aside, I believe KDE and some other desktop environments have "restore previous session" options although, last time I checked this did not extend to restoring window positions. Perhaps this could make a useful gnome shell extension?

Collapse
 
ricardo_borges profile image
Ricardo Borges

I use dual boot, so suspend mode is not a option for me. I could use hibernate but I have learn more writing my own solution.

Collapse
 
twright profile image
Thomas Wright • Edited

Fair enough; I do see the value of such a tool even if I would not necessarily use it. This is one of the reasons I very rarely boot into windows these days, alongside the hour of Windows updates I incur every time I do so. I also keep too much other state in RAM such as my browser tabs, my tmux session, and my open jupyter notebooks to want to reboot frequently. My applications also tend to be spread over ~8 virtual desktops, which would be interesting to try and restore programmatically.

Collapse
 
pgronkievitz profile image
Patryk Gronkiewicz

Wouldn't it be easier to use tiling window manager rather than regular desktop environment? Most of them support floating windows, so I don't think it's the problem

Collapse
 
sakshatshinde profile image
Sakshat

Exactly what I was thinking. There are some easy to configure tiling window managers like awesome or i3 with a good amount of tutorials for beginners.

Collapse
 
kvanrooyen profile image
Keagan Van Rooyen

Anything like that for Mac?

Collapse
 
pgronkievitz profile image
Patryk Gronkiewicz
Collapse
 
gwutama profile image
Galuh Utama • Edited

Not bad!

I’m too lazy though, so I just put my laptop and pc to sleep so I can get everything ready just as I left them.

Collapse
 
beernutz profile image
beernutz • Edited

Here are a couple options for doing this in Windows.
Free: winsize2.sourceforge.net
Paid: $29, but MUCH more full-featured: displayfusion.com

Both of them are super easy to set up, and don't require coding or text file editing if you would rather spend your mental cycles on other things.

Collapse
 
johannesjo profile image
Johannes Millan

Another a little bit more flexible alternative for doing this (sorry for the shameless self promotion):
github.com/johannesjo/linux-window...

Collapse
 
ricardo_borges profile image
Ricardo Borges

It's okay, I wrote these posts to share knowledge and I'm glad to see comments like yours. I'll take look at it later.

Collapse
 
jamesbright profile image
James Ononiwu

this is lovely and intuitive