I want to start chromium-browser minimized using bash in a terminal.
Currently using chromium-browser to open Chromium. But how to open it as minimized using a bash command.
Using wmctrl, (on Debian-based systems install with apt install wmctrl), to send commands to any NetWM window manager:
chromium-browser && \
last_chrom=$(wmctrl -l |
grep -i chrom | tail -1 |
while read a b ; do echo $a ; done) ; \
wmctrl -ir $last_chrom -b toggle,hidden
How it works:
Start the browser.
Save the window identity number of the most recent invocation of chromium-browser in the variable $last_chrom.
Use wmctrl to hide that window.
(Optional) To have the window close after running for a minute, add one more line:
chromium-browser && \
last_chrom=$(wmctrl -l |
grep -i chrom | tail -1 |
while read a b ; do echo $a ; done) ; \
wmctrl -ir $last_chrom -b toggle,hidden ; \
{ sleep 1m && wmctrl -ic $last_chrom ; } &
Related
I have this function on my bash script:
sudo tshark -i eth0 -T fields -e ip.src -e dns.qry.name -Y "dns.qry.name~." -q 1>>log.txt 2>/dev/null &
while true
do
cat log.txt
done
it is capturing ips and domain names in live mode and save them into log file.
how can configure this live mode to be terminated by pressing a key?
Using tee to watch log and send the command to background, then read input to terminate script
tshark -i eth0 -T fields -e ip.src -e dns.qry.name -Y "ip" -q 2>/dev/null | tee log.txt &
read -n1 c && echo "Got key $c"
exit
Note: running the command in a console will terminate it :-p
I want to write a script that opens a shell with a few tabs, and i want each tab to execute somthing automaticly. for some reason when i pipe the commands it does not work.
gnome-terminal \
--tab-with-profile=Titleable -t "A" \
--tab-with-profile=Titleable -t "B" -e "sudo tail -f /var/log/syslog" \
--tab-with-profile=Titleable -t "C" -e "sudo tail -f /var/log/syslog | grep txt"
for some reason for Tab A&B work but in C the grep txt is ignored.
Anyone know why?
Thanks
Mat
Use a shell to call your command:
gnome-terminal \
--tab-with-profile=Titleable -t "A" \
--tab-with-profile=Titleable -t "B" -e "sudo tail -f /var/log/syslog" \
--tab-with-profile=Titleable -t "C" -e 'sh -c "sudo tail -f /var/log/syslog | grep txt"'
I have a shell script that is supposed to kill a detached screen session if it exists. The script is
if ! screen -list | grep -q "ScreenName"; then
screen -S ScreenName -X quit
fi
Unfortunately it seems that the screen -S ... -X quit command always runs bc when I run the script and the screen session doesn't exist it still outputs "No screen sessions found." When I remove the ! and the screen session is running, it doesn't kill the running session.
What could the problem be? Thanks
To get rid of the "No screen sessions found" message, redirect the stderr of screen:
screen -list 2>/dev/null
Next, keep in mind that -X doesn't work if the session is password protected.
Then, use -r to let screen know you only want to kill detached sessions, and there's no more need for grep and if.
Putting it all together:
screen -r -S "ScreenName" -X quit 2>/dev/null
grep has a confusing convention for return codes. It returns 0 when a string is found and returns 1 when there is no match. You should omit the ! in the condition.
#Sir Athos answer is pretty good, if you don't want to ignore valid errors, or just want additional ways to do things in the future, you can use this as a reference:
screen -ls 2>&1 | grep '(Detached)' | grep -o 'ScreenName' | xargs -I{} -n 1 -r screen -r -S {} -X quit
screen -ls 2>&1 List sessions, all output to stdout
grep '(Detached)' Filter for detached sessions
grep -o 'ScreenName' Filter for ScreenName and only output ScreenName
xargs -I{} -n 1 -r screen -r -S {} -X quit Run output through xargs -n 1 one at a time, -r don't run if there is no output, -I{} use {} as the replacement location for your argument since it's not at the end, and run your command
Code Sample:
evan> screen -ls
There are screens on:
15491.pts-2.x (08/29/2013 10:43:53 AM) (Detached)
31676.pts-41.x (08/28/2013 10:55:00 AM) (Attached)
2 Sockets in /var/run/screen/S-evan.
evan> screen -ls 2>&1 | grep '(Detached)' | grep -o '15491.pts-2.x' | xargs -I{} -n 1 -r screen -r -S {} -X quit
evan> screen -ls
There is a screen on:
31676.pts-41.x (08/28/2013 10:55:00 AM) (Attached)
1 Socket in /var/run/screen/S-evan.
evan> screen -ls 2>&1 | grep '(Detached)' | grep -o '15491.pts-2.x' | xargs -I{} -n 1 -r screen -r -S {} -X quit
evan>
I need to execute the following grep query as an argument for konsole (the kde terminal)
grep -R -i -n -A 2 -B 2 --color=always -R "searchtext" * | less -R
works for the current terminal.
konsole --workdir `pwd` -e grep -R -i -n -A 2 -B 2 --color=always -R "searchtext" * | less -R
works, but the konsole window displays the grep query without less pipe.
Ideally I want konsole to spawn as seperate process with konsole &
and send the grep command with less as an argument for konsole -e
You need to run the pipe in a shell.
konsole --workdir pwd -e bash -c 'grep -R -i -n -A 2 -B 2 --color=always -R "searchtext" * | less -R'
Can I close a window using wmctrl that is running in wine on Ubuntu?
For context:
$ wmctrl -m
Name: compiz
Class: N/A
PID: N/A
Window manager's "showing the desktop" mode: OFF
Also:
$ wmctrl -l
0x0240a3be -1 mjol N/A
0x02000003 0 mjol Top Expanded Edge Panel
0x0200004c 0 mjol Bottom Expanded Edge Panel
0x01e00024 0 mjol x-nautilus-desktop
0x04800253 0 mjol using wmctrl to close windows - Stack Overflow - Google Chrome
0x03c0c8c3 0 mjol Terminal
0x03c53f25 0 mjol Terminal
0x04400001 0 mjol Untitled - SketchUp
0x04400003 0 mjol Instructor
0x04400009 0 mjol SketchUp
The window I want to close is the last one:
0x04400009 0 mjol SketchUp
I've tried the following:
$ wmctrl -c "SketchUp"
$ wmctrl -c 0x04400009
$ wmctrl -i 0x04400009
$ wmctrl -c -i 0x04400009
But nothing works.
Maybe a little late, but first seen now.
Reading the info for wmctrl, it says that the correct syntax is 'options' before actions, and -i is an option, -c an action. Try wmctrl -i -c 0x04400009
I was having the same question and just found how to do it!
Here's the one-liner that will gracefully close all Google Chrome windows:
wmctrl -lix |grep 'Google-chrome'|cut -d ' ' -f 1 |xargs -i% wmctrl -i -c %
Explanation:
wmctrl -lix list all windows including their Id and Class
grep 'Google-chrome' grep only windows with Google-chrome class (this is important because when you use a site with the app/shortcut option it gets it own class like 'calendar.google.com.Google-chrome'
cut -d ' ' -f 1 cuts the output to get only the IDs column
xargs -i% wmctrl -i -c % passes each ID to the wmctrl using the ID option -i and close command -c
Note: the xargs only worked when I used the -i option to specify replace-string. Otherwise it would only act on the first item.
According to the man page, you should select the window first using a select option, like -r and -a, exemple :
$ wmctrl -l
0x01800006 0 hostname Terminal - byobu
$ wmctrl -a Terminal
Here indeed selects (and raises + focus due to -a) the terminal window.
Then you can use a resize / move option such as -e gravity,X,Y,width,height
As for your question, I just tested this :
$ wmctrl -l
0x01800006 0 machine_hostname - byobu
0x06800002 0 moe Microsoft Excel - Classeur1
And Excel (obviously running in Wine) closed gracefully when I entered
$ wmctrl -c Microsoft
Plenty of additional info here.