[SOLVED]xdotool, minimize window by name(not by name, but solved)
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Topics in this forum are automatically closed 6 months after creation.
[SOLVED]xdotool, minimize window by name(not by name, but solved)
Seems I tried every combination I can think of and I can not get this to work.
If I use the window ID number it works, trouble is numbers keep changing, so not much good in a script.
eg.
xdotool windowminimize 0x03600008
works, but
xdotool windowminimize Calculator
does not,
nor does,
xdotool windowminimize "Calculator"
xdotool search --classname Calculator windowminimize
xdotool search --name "Calculator" windowminimize (this one produce no output error, so is syntax OK ?)
And I have googled for a good while going in circles it seems.
This seemed pretty close,
https://askubuntu.com/questions/703628/ ... m-terminal
saying to minimize a window, do,
xdotool windowminimize <window_id>
and window_id can be substituted with, $(xdotool getactivewindow)
That did not work either.
First answer here https://askubuntu.com/questions/4876/ca ... mmand-line 42 votes, does not work.
Anyway is there a way to make it work with the window name ?
And BTW today is the first time I "played" with xdotool.
EDIT, PS, this is not even for myself, just looking for an easy way to solve this thread viewtopic.php?t=409441
If I use the window ID number it works, trouble is numbers keep changing, so not much good in a script.
eg.
xdotool windowminimize 0x03600008
works, but
xdotool windowminimize Calculator
does not,
nor does,
xdotool windowminimize "Calculator"
xdotool search --classname Calculator windowminimize
xdotool search --name "Calculator" windowminimize (this one produce no output error, so is syntax OK ?)
And I have googled for a good while going in circles it seems.
This seemed pretty close,
https://askubuntu.com/questions/703628/ ... m-terminal
saying to minimize a window, do,
xdotool windowminimize <window_id>
and window_id can be substituted with, $(xdotool getactivewindow)
That did not work either.
First answer here https://askubuntu.com/questions/4876/ca ... mmand-line 42 votes, does not work.
Anyway is there a way to make it work with the window name ?
And BTW today is the first time I "played" with xdotool.
EDIT, PS, this is not even for myself, just looking for an easy way to solve this thread viewtopic.php?t=409441
Last edited by rickNS on Mon Dec 11, 2023 11:23 am, edited 1 time in total.
Mint 20.0, and 21.0 MATE on Thinkpads, 3 X T420, T450, T470, and X200
-
- Level 2
- Posts: 98
- Joined: Sun Mar 13, 2022 8:30 am
- Location: virgo supercluster, milky way galaxy, solar system, earth
Re: xdotool, minimize window by name
I think I remember having problems with xdotool after distro update. I used wmctrl instead for window control.
It's all a vague memory though. I could be wrong.
this should do it
sleep 1 is to let the program load first. you could replace it with a condition
you can change
It's all a vague memory though. I could be wrong.
this should do it
Code: Select all
sleep 1 && wmctrl -r "windowname" -b toggle,hidden & RunSomeProgram
Code: Select all
while ! [[ "$(wmctrl -l)" =~ "windowname" ]]
do
sleep 1
done &&
wmctrl -r "windowname" -b toggle,hidden &
RunSomeProgram
sleep 1
to less to reduce lag but it will eventually increase cpu. Try sleep 0.3
Re: xdotool, minimize window by name
Did not seem to work.Coffeeee wrote: ⤴Mon Dec 11, 2023 7:03 am
this should do itCode: Select all
sleep 1 && wmctrl -r "windowname" -b toggle,hidden & RunSomeProgram
Even with Calculator (as test program) already open this bit,
wmctrl -r "Calculator" -b toggle,hidden
did not work, also tried "gnome-calculator", and the "numerical id". No difference.
Mint 20.0, and 21.0 MATE on Thinkpads, 3 X T420, T450, T470, and X200
Re: xdotool, minimize window by name
If minimizing the window with ID works, why not get the window ID with wmctrl and minimize it with xdotool? So do a list with wmctrl, then grep the window name you want and awk the window ID.
Rekenmachine is dutch for Calculator, so change it to whatever you want to minimize.
Rekenmachine is dutch for Calculator, so change it to whatever you want to minimize.
Code: Select all
xdotool windowminimize $(wmctrl -l | grep Rekenmachine | awk '{print $1}')
Re: xdotool, minimize window by name
Excellent, thanks.Koentje wrote: ⤴Mon Dec 11, 2023 10:08 am If minimizing the window with ID works, why not get the window ID with wmctrl and minimize it with xdotool? So do a list with wmctrl, then grep the window name you want and awk the window ID.
Rekenmachine is dutch for Calculator, so change it to whatever you want to minimize.
Code: Select all
xdotool windowminimize $(wmctrl -l | grep Rekenmachine | awk '{print $1}')
That works, and your script solves that other thread nicely too.
I was trying to use cut to get the id into a varible,
wmctrl -l | grep Calculator | cut -b 1-10
, but I kept getting errors, and the terminal was left open, disown did not seem to help. I am not a coder by any stretch but I tried haha.Thanks, very much.
Marking solved
Mint 20.0, and 21.0 MATE on Thinkpads, 3 X T420, T450, T470, and X200
Re: [SOLVED]xdotool, minimize window by name(not by name, but solved)
Thanks!
I don't use cut too often.. awk for this is way better IMO.. it doesn't depend on length of characters you want to grab. $1 grabs anything until the first space. $2 grabs anything from the first space to the second space and so on. If you use the -F option you can specify another separator.
Say this line is in a string called line and | is the seperator
And you want the number 456 out of it
This wil get you 123789
If you want a space between them
I don't use cut too often.. awk for this is way better IMO.. it doesn't depend on length of characters you want to grab. $1 grabs anything until the first space. $2 grabs anything from the first space to the second space and so on. If you use the -F option you can specify another separator.
Say this line is in a string called line and | is the seperator
123|456|789
And you want the number 456 out of it
echo "$line" | awk -F'|' '{print $2}'
This wil get you 123789
echo "$line" | awk -F'|' '{print $1 $3}'
If you want a space between them
echo "$line" | awk -F'|' '{print $1" "$3}'
Re: [SOLVED]xdotool, minimize window by name(not by name, but solved)
If you have a separator character, cut does the job fine and is more readable IMHO. Aside if you want to print multiple fields without an output delimiter it's a bit noisy:Koentje wrote: ⤴Mon Dec 11, 2023 12:27 pm I don't use cut too often.. awk for this is way better IMO.. it doesn't depend on length of characters you want to grab. $1 grabs anything until the first space. $2 grabs anything from the first space to the second space and so on. If you use the -F option you can specify another separator.
Code: Select all
$ echo "$line" | cut -d'|' -f2
456
$ echo "$line" | cut -d'|' -f1,3
123|789
$ echo "$line" | cut -d'|' -f1,3 --output-delimiter=''
123789
Re: [SOLVED]xdotool, minimize window by name(not by name, but solved)
So not to beat a dead horse, I have another question, if either of you can, or would be so kind to explain this.xenopeek wrote: ⤴Mon Dec 11, 2023 12:59 pm
If you have a separator character, cut does the job fine and is more readable IMHO. Aside if you want to print multiple fields without an output delimiter it's a bit noisy:Code: Select all
$ echo "$line" | cut -d'|' -f2 456 $ echo "$line" | cut -d'|' -f1,3 123|789 $ echo "$line" | cut -d'|' -f1,3 --output-delimiter='' 123789
OK so I can cut the window ID like this,
Code: Select all
wmctrl -l | grep Calculator | cut -d ' ' -f1
0x03600008
Code: Select all
wmctrl -l | grep Calculator | awk '{print $1}'
0x03600008
Code: Select all
xdotool windowminimize $(wmctrl -l | grep Calculator | cut -d ' ' f1)
cut: you must specify a list of bytes, characters, or fields
Try 'cut --help' for more information.
There are no windows in the stack
Invalid window '%1'
Usage: windowminimize [options] [window=%1]
--sync - only exit once the window has minimized (is not visible)
If no window is given, %1 is used. See WINDOW STACK in xdotool(1)
Unlike the command with awk by
Which works without error, and the window minimizes.
Mint 20.0, and 21.0 MATE on Thinkpads, 3 X T420, T450, T470, and X200
Re: [SOLVED]xdotool, minimize window by name(not by name, but solved)
If i run the script like this
...it works!
Code: Select all
#!/bin/bash
gnome-calculator &
while [ "$(wmctrl -l | grep Calculator)" = "" ]; do
echo "Waiting..." > /dev/null
done
xdotool windowminimize $(wmctrl -l | grep Calculator | cut -d' ' -f1)