*Solved Enough for now* Script to auto launch nemo window & auto snap them to corners

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
motoryzen
Level 10
Level 10
Posts: 3427
Joined: Sun Dec 08, 2019 12:25 am

*Solved Enough for now* Script to auto launch nemo window & auto snap them to corners

Post by motoryzen »

-- I'd like to have/create a script that I can run at system start up where it auto launches specific Nemo directories and immediately auto snaps each directory window to different corners of the screen.

For example one Nemo window would be my Movies folder, another would be my gopro folder on a different drive, and another would be something else. Movies would autosnap in the upper left corner, gopro to the upper right and the something else would be the bottom right corner..

Is this possible?

I've look on here but couldn't find where someone already created this post and couldn't find any non-rabbit endless hole topics out there that are as close to this as possible. --
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 4 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Mint 21.2 Cinnamon 5.8.4
asrock x570 taichi ...bios p5.00
ryzen 5900x
128GB Kingston Fury @ 3600mhz
Corsair mp600 pro xt NVME ssd 4TB
three 4TB ssds
dual 1TB ssds
Two 16TB Toshiba hdd's
24GB amd 7900xtx vid card
Viewsonic Elite UHD 32" 144hz monitor
User avatar
Termy
Level 12
Level 12
Posts: 4254
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: Script to auto launch nemo windows and auto snap them to corners

Post by Termy »

Should be doable. You could probably do some of this with xdotool(1).
I'm also Terminalforlife on GitHub.
motoryzen
Level 10
Level 10
Posts: 3427
Joined: Sun Dec 08, 2019 12:25 am

Re: Script to auto launch nemo windows and auto snap them to corners

Post by motoryzen »

-- Well read all I could find about xdotool, but I'm at a dead end. I tried every combo I could figure out via the xdo tool help page, but nothing works. Nothing does anything.

Is there a way to just create a combo command where to it launches a specific nemo folder/directory and then immediately auto executes super key+arrow keys as if I manually did both? --
Mint 21.2 Cinnamon 5.8.4
asrock x570 taichi ...bios p5.00
ryzen 5900x
128GB Kingston Fury @ 3600mhz
Corsair mp600 pro xt NVME ssd 4TB
three 4TB ssds
dual 1TB ssds
Two 16TB Toshiba hdd's
24GB amd 7900xtx vid card
Viewsonic Elite UHD 32" 144hz monitor
User avatar
Termy
Level 12
Level 12
Posts: 4254
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: Script to auto launch nemo windows and auto snap them to corners

Post by Termy »

motoryzen wrote: Fri Mar 19, 2021 9:46 pm Is there a way to just create a combo command where to it launches a specific nemo folder/directory and then immediately auto executes super key+arrow keys as if I manually did both? --
Maybe something like this:

Code: Select all

nemo && { sleep 0.5s; xdotool key --window `xdotool getactivewindow` 'Super+Right'; }
Which presumes Nemo is opened up activated. I'm confident there's a far better way to do it, but that's just a rough idea. Added sleep(1) time there because there needs to be enough time for the GUI to open and be active; adjust as needed for your system.
I'm also Terminalforlife on GitHub.
Welcome
Level 6
Level 6
Posts: 1026
Joined: Wed Aug 19, 2020 11:38 am

Re: Script to auto launch nemo windows and auto snap them to corners

Post by Welcome »

motoryzen wrote: Mon Mar 15, 2021 9:23 pm -- I'd like to have/create a script that I can run at system start up where it auto launches specific Nemo directories and immediately auto snaps each directory window to different corners of the screen.

For example one Nemo window would be my Movies folder, another would be my gopro folder on a different drive, and another would be something else. Movies would autosnap in the upper left corner, gopro to the upper right and the something else would be the bottom right corner..

Is this possible?

I've look on here but couldn't find where someone already created this post and couldn't find any non-rabbit endless hole topics out there that are as close to this as possible. --
You'll need to change the directory names to what you want, and you may want to change the size of the windows.... :D

Code: Select all

#!/bin/bash

# Get the max dimensions of the current display
maxhor=$(xrandr | awk '/current/ { print $8 }')
maxver=$(xrandr | awk '/current/ { print $10 }' | cut -d, -f1)

# Define the desired size of the windows
width=700
height=400

# Calc the horizontal location of the moved window on the right
horloc=$(( maxhor - width ))

# Calc the vertical location of the moved window at the bottom
verloc=$(( maxver - height ))

# Using termy format... with a few changes
nemo $HOME/Videos && { sleep 0.5s; xdotool getactivewindow windowsize $width $height windowmove 0 0; }
nemo $HOME/Music && { sleep 0.5s; xdotool getactivewindow windowsize $width $height windowmove $horloc 0; }
nemo $HOME/Downloads && { sleep 0.5s; xdotool getactivewindow windowsize $width $height windowmove 0 $verloc; }
nemo $HOME/Pictures && { sleep 0.5s; xdotool getactivewindow windowsize $width $height windowmove $horloc $verloc; }

exit 0

# end of file
User avatar
Termy
Level 12
Level 12
Posts: 4254
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: Script to auto launch nemo windows and auto snap them to corners

Post by Termy »

Nice one, Welcome. Optimized the resolution fetching, and tidied up the code a bit by using a function. Also removed the redundant `exit` at the end. The script is already exiting, at that point. :P I placed the important variables the user is to set to the top of the script, because that's typically where those go.

My parsing is assuming the output in my version of xrandr(1) is the same format as it usually always is; don't think it's changed in all these years I've used Linux.

Code: Select all

#!/bin/bash

# Define the desired size of the windows
width=700
height=400

# Get the max dimensions of the current display
read -a line <<< "$(xrandr)"
maxhor=${line[7]}
maxvir=${line[9]%,}

# Calc the horizontal location of the moved window on the right
horloc=$(( maxhor - width ))

# Calc the vertical location of the moved window at the bottom
verloc=$(( maxver - height ))

# Usage: xdo <WIDTH> <HEIGHT> <X> <Y>
xdo() {
	sleep 0.5s
	xdotool getactivewindow windowsize $1 $2 windowmove $3 $4
}

# Using termy format... with a few changes
nemo "$HOME"/Videos && xdo $width $height 0 0
nemo "$HOME"/Music && xdo $width $height $horloc 0
nemo "$HOME"/Downloads && xdo $width $height 0 $verloc
nemo "$HOME"/Pictures && xdo $width $height $horloc $verloc

# end of file
I'm also Terminalforlife on GitHub.
motoryzen
Level 10
Level 10
Posts: 3427
Joined: Sun Dec 08, 2019 12:25 am

Re: Script to auto launch nemo windows and auto snap them to corners

Post by motoryzen »

Termy wrote: Sat Mar 20, 2021 11:09 am
motoryzen wrote: Fri Mar 19, 2021 9:46 pm Is there a way to just create a combo command where to it launches a specific nemo folder/directory and then immediately auto executes super key+arrow keys as if I manually did both? --
Maybe something like this:

Code: Select all

nemo && { sleep 0.5s; xdotool key --window `xdotool getactivewindow` 'Super+Right'; }
Which presumes Nemo is opened up activated. I'm confident there's a far better way to do it, but that's just a rough idea. Added sleep(1) time there because there needs to be enough time for the GUI to open and be active; adjust as needed for your system.
Winner winner chicken dinner!!!! Adding +up directly after "+Right"and it auto snaps the window to upper right corner. Also I confirmed instead adding +Down ( must be capital D ..wont work with lower case d ) will auto snap it to the bottom right corner, as well as replacing +Right with +LEFT and/or otherdirections and it just works!!!

Lastly you can add the exact directory/folder path ( e.g. nemo /home/username/Pictures && { sleep etc..etc..etc } and it just works

Finally I confirmed with LM 20.1 Cinnamon 4.8.6 that it . IS . necessary that Nemo is already running first ( meaning Nemo-desktop process as shown in gnome-system-monitor for example...be it one nemo folder already open or not open as long as Nemo-desktop process is running.( which by default...stock in LM Cinnamon is alwaysis running upon boot up )

You're awesome for building or finding this. This is precisely what I was looking for. Now I can just replace the three folder nemo autolaunch custom commands I made with three of these.

** Last part of this is figuring out how to make each folder auto launch at startup.

I tried just pasting that exact command as a custom command in Startup Applications and with a variety of delays, but nothing happens..even when I create a a normal nemo /home/username/Documents folder launcher and that works and delayed these new custom nemo /path && etc commands...they don't auto launch upon boot up yet.

I'm stoked though...almost there.

---
Last edited by motoryzen on Sat Mar 20, 2021 6:19 pm, edited 1 time in total.
Mint 21.2 Cinnamon 5.8.4
asrock x570 taichi ...bios p5.00
ryzen 5900x
128GB Kingston Fury @ 3600mhz
Corsair mp600 pro xt NVME ssd 4TB
three 4TB ssds
dual 1TB ssds
Two 16TB Toshiba hdd's
24GB amd 7900xtx vid card
Viewsonic Elite UHD 32" 144hz monitor
User avatar
Termy
Level 12
Level 12
Posts: 4254
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: Script to auto launch nemo windows and auto snap them to corners

Post by Termy »

I didn't write xdotool(1); that badge of honor goes to Jordan Sissel and contributors. The one-liner and other code I've submitted here are the only things I wrote. :lol: Also, the reason those words (IE: Shift) need to be capitalized is because that's the 'proper' name -- check out xev(1).
Last edited by Termy on Sat Mar 20, 2021 6:04 pm, edited 1 time in total.
I'm also Terminalforlife on GitHub.
motoryzen
Level 10
Level 10
Posts: 3427
Joined: Sun Dec 08, 2019 12:25 am

Re: ** SOLVED ** Script to auto launch nemo window & auto snap them to corners

Post by motoryzen »

-- Thanks everyone for your input. I might experiment with the bash file deal later, but that nemo && line command so far is working perfectly when manually launched. Now it's just a matter of getting each command to auto launch upon system boot up..Cheers --
Mint 21.2 Cinnamon 5.8.4
asrock x570 taichi ...bios p5.00
ryzen 5900x
128GB Kingston Fury @ 3600mhz
Corsair mp600 pro xt NVME ssd 4TB
three 4TB ssds
dual 1TB ssds
Two 16TB Toshiba hdd's
24GB amd 7900xtx vid card
Viewsonic Elite UHD 32" 144hz monitor
motoryzen
Level 10
Level 10
Posts: 3427
Joined: Sun Dec 08, 2019 12:25 am

Re: Script to auto launch nemo windows and auto snap them to corners

Post by motoryzen »

Welcome wrote: Sat Mar 20, 2021 12:54 pm
motoryzen wrote: Mon Mar 15, 2021 9:23 pm -- I'd like to have/create a script that I can run at system start up where it auto launches specific Nemo directories and immediately auto snaps each directory window to different corners of the screen.

For example one Nemo window would be my Movies folder, another would be my gopro folder on a different drive, and another would be something else. Movies would autosnap in the upper left corner, gopro to the upper right and the something else would be the bottom right corner..

Is this possible?

I've look on here but couldn't find where someone already created this post and couldn't find any non-rabbit endless hole topics out there that are as close to this as possible. --
You'll need to change the directory names to what you want, and you may want to change the size of the windows.... :D

Code: Select all

#!/bin/bash

# Get the max dimensions of the current display
maxhor=$(xrandr | awk '/current/ { print $8 }')
maxver=$(xrandr | awk '/current/ { print $10 }' | cut -d, -f1)

# Define the desired size of the windows
width=700
height=400

# Calc the horizontal location of the moved window on the right
horloc=$(( maxhor - width ))

# Calc the vertical location of the moved window at the bottom
verloc=$(( maxver - height ))

# Using termy format... with a few changes
nemo $HOME/Videos && { sleep 0.5s; xdotool getactivewindow windowsize $width $height windowmove 0 0; }
nemo $HOME/Music && { sleep 0.5s; xdotool getactivewindow windowsize $width $height windowmove $horloc 0; }
nemo $HOME/Downloads && { sleep 0.5s; xdotool getactivewindow windowsize $width $height windowmove 0 $verloc; }
nemo $HOME/Pictures && { sleep 0.5s; xdotool getactivewindow windowsize $width $height windowmove $horloc $verloc; }

exit 0

# end of file
-- @Welcome.

Awesome!!

This is a more efficient way to reach my goal.

Now I must figure out how to get what I call Line 3 (nemo $HOME/Downloads && etc etc ) to snap to the bottom right hand corner ( given my monitor is 2560x1440 total rez. I figured out the precisely perfect window size via a tiling aka snap is 1280 width and 720 height at the " Define the desized size of the windows " part up top) That's the only line I need to figure out to make it snap at bottom right corner instead of it right now as of your code..snapping to the upper left corner. --
Mint 21.2 Cinnamon 5.8.4
asrock x570 taichi ...bios p5.00
ryzen 5900x
128GB Kingston Fury @ 3600mhz
Corsair mp600 pro xt NVME ssd 4TB
three 4TB ssds
dual 1TB ssds
Two 16TB Toshiba hdd's
24GB amd 7900xtx vid card
Viewsonic Elite UHD 32" 144hz monitor
motoryzen
Level 10
Level 10
Posts: 3427
Joined: Sun Dec 08, 2019 12:25 am

Re: ** Almost Solved ** Script to auto launch nemo window & auto snap them to corners

Post by motoryzen »

** update**
-- Ok..so The method I'm trying to deal with now is this:

I have an executable file located in my Home folder called Nemobashscrip.sh which contains the following if you open it up via text editor

Code: Select all

#!/bin/bash

# Define the desired size of the windows
width=1280
height=720

# Get the max dimensions of the current display
read -a line <<< "$(xrandr)"
maxhor=${line[7]}
maxvir=${line[9]%,}

# Calc the horizontal location of the moved window on the right
horloc=$(( maxhor - width ))

# Calc the vertical location of the moved window at the bottom
verloc=$(( maxver - height ))

# Usage: xdo <WIDTH> <HEIGHT> <X> <Y>
xdo() {
	sleep 0.02s
	xdotool getactivewindow windowsize $1 $2 windowmove $3 $4
}

# Using termy format... with a few changes
nemo '/mnt/10TB toshiba hdd/Movies and Series' && { sleep 0.1s; xdotool key --window `xdotool getactivewindow` 'Super+Left+Up'; }
nemo '/mnt/4TB ssd Games,et/Game Shortcuts' && { sleep 0.1s; xdotool key --window `xdotool getactivewindow` 'Super+Right+Up'; }
nemo '/mnt/GoPro 1TB Backup' && { sleep 0.1s; xdotool key --window `xdotool getactivewindow` 'Super+Right+Down'; }

# end of file
So as long as at least one nemo folder is already open ( which in this case is my home folder containing that .sh file) it just works.

Now when I try to add that as the only Nemo....coherent launching thing with Startup Applications....it only launches one of my three Nemo windows ( the top option which is the Movies and Series folder...) and it doesn't snap/tile it...instead it opens it dead center in a smaller window size.

However -- If I add, with a much shorter delay, a separate Nemo custom command ( doesn't matter where the folder/directory path is), My mission is accomplish but with that 1st extra separate Nemo window that launched first.

Worst case, if this is how I must accomplish my mission...it's not a deal breaker, but I was hoping for a result without having to do a fourth or extra Nemo window launching first to allow this 3 window nemo with auto snap- command to work.

I tried that Bash script adding it to /etc/init.d , etc/xdg/autostart, and both, but it only launches the one Nemo window ( Movies and series) or doesn't work at all be it executable or not executable. I'm unsure what I'm missing here ... *shrugs*

**** Now this next part is odd to me***

When I left click and drag that script file directly into terminal window ( it doesnt matter if one or no nemo windows are launched/open) it just works...perfectly.

It's as if I could just copy and paste whatever beginning command into a " custom command" within Startup Applications ( beginning command for example being nemo /home/username/Pictures to make it autolaunch the pictures folder upon system boot up) of using Terminal to launch that script file via '/home/user name/Nemobashscript.sh' Then is 100% mission accomplished perfectly.

Is that option possible and if so..what is that beginning command please? --
Mint 21.2 Cinnamon 5.8.4
asrock x570 taichi ...bios p5.00
ryzen 5900x
128GB Kingston Fury @ 3600mhz
Corsair mp600 pro xt NVME ssd 4TB
three 4TB ssds
dual 1TB ssds
Two 16TB Toshiba hdd's
24GB amd 7900xtx vid card
Viewsonic Elite UHD 32" 144hz monitor
motoryzen
Level 10
Level 10
Posts: 3427
Joined: Sun Dec 08, 2019 12:25 am

Re: ** Almost Solved ** Script to auto launch nemo window & auto snap them to corners

Post by motoryzen »

-- Unless there is something I'm missing, which there could be xD , doing the command without quotes "gnome-terminal -e bashscript.sh file" ( meaning launching gnome terminal and then executing that script file) only launches just a single nemo window with that top nemo path selection out of the three I want to launch.....if another nemo window has not already launched first.

So unless something else can confirm otherwise, it looks like the closest I'll get it having a separate custom command of Nemo ( matters not the full file path) launching just before my bash script command to get what I want.

I'll marked this as Solved Enough for Now and in the future if anyone has an idea letting me still auto launch all three windows snapped in the corners without the need for the 4th launching first, I'm all eyes.

Thanks for everyone's help and input.

Cheers--
Mint 21.2 Cinnamon 5.8.4
asrock x570 taichi ...bios p5.00
ryzen 5900x
128GB Kingston Fury @ 3600mhz
Corsair mp600 pro xt NVME ssd 4TB
three 4TB ssds
dual 1TB ssds
Two 16TB Toshiba hdd's
24GB amd 7900xtx vid card
Viewsonic Elite UHD 32" 144hz monitor
Welcome
Level 6
Level 6
Posts: 1026
Joined: Wed Aug 19, 2020 11:38 am

Re: *Solved Enough for now* Script to auto launch nemo window & auto snap them to corners

Post by Welcome »

Some quick thoughts...
  1. When you tried Startup Applications, what startup delay did you use? Do you need help in calling a script file from Startup Applications?
  2. You might need to change the current 'sleep 0.5s' (or 'sleep 0.1s') to a greater value, depending on your hardware and the activity in progress at startup.
  3. You might need to add a test to see if the directory exists before trying to open it. I'd use a loop to test for the existance of the directory and 'sleep 1.0s' (or something like that) until the directory exists. And maybe a drop out test if the directory doesn't exist after X seconds.
  4. There is a way to test for a Window being opened and ready for xdotool commands, but this will add a lot more code.
Best to pick the low hanging fruit first:
  • Fix the typo (see below),
  • Check and increase Startup Applications delay,
  • Increase 'sleep 0.5s' delay.
Then, if those don't work:
  • Add a test to see if the directory exists,
  • Add a test to see if the Window is open and ready.
@termy
Termy wrote: Sat Mar 20, 2021 5:36 pm ... Optimized the resolution fetching, and tidied up the code a bit by using a function. Also removed the redundant `exit` at the end. The script is already exiting, at that point. :P I placed the important variables the user is to set to the top of the script, because that's typically where those go.
Thanks! Much better version! :D

Minor typo (but significant):

Code: Select all

# Get the max dimensions of the current display
read -a line <<< "$(xrandr)"
maxhor=${line[7]}
maxvir=${line[9]%,}
Change maxvir to maxver, like this...

Code: Select all

# Get the max dimensions of the current display
read -a line <<< "$(xrandr)"
maxhor=${line[7]}
maxver=${line[9]%,}
User avatar
Termy
Level 12
Level 12
Posts: 4254
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: *Solved Enough for now* Script to auto launch nemo window & auto snap them to corners

Post by Termy »

Thanks. :) It's always the typos... :lol:
I'm also Terminalforlife on GitHub.
Locked

Return to “Scripts & Bash”