You are not logged in.
This is one of the goodies you can find in Vsido. It needs wmctrl.
launch
#!/bin/bash
# This script acts as a launcher for apps that observes the following rules:
# 1. If the app is not running, then start it up
# 2. If the app is running, don't start a second instance, instead:
# 2a. If the app does not have focus, give it focus
# 2b. If the app has focus, minimize it
# Reference link: http://forum.xfce.org/viewtopic.php?id=6168&p=1
# there has to be at least one parameter, the name of the file to execute
if [ $# -lt 1 ]
then
echo "Usage: `basename $0` {executable_name parameters}"
exit 1
fi
BNAME=`basename $1`
# test to see if program is already running
if [ "`wmctrl -lx | tr -s ' ' | cut -d' ' -f1-3 | grep -i $BNAME`" ]; then
# means it must already be running
ACTIV_WIN=$(xdotool getactivewindow getwindowpid)
LAUNCH_WIN=$(ps -ef | grep "$BNAME" | grep -v grep | tr -s ' ' | cut -d' ' -f2 | head -n 1)
if [ "$ACTIV_WIN" == "$LAUNCH_WIN" ]; then
# launched app is currently in focus, so minimize
xdotool getactivewindow windowminimize
else
# launched app is not in focus, so raise and bring to focus
for win in `wmctrl -lx | tr -s ' ' | cut -d' ' -f1-3 | grep -i $BNAME | cut -d' ' -f1`
do
wmctrl -i -a $win
done
fi
exit
else
# start it up
$*&
fi
exit 0
IIRC by default in Vsido it's used everywhere in the Fluxbox menu and the keys config files, but I prefer using it for certain apps like web browsers, editors like medit or geany, file managers like spacefm, xfce4-terminal (they all have tabs so a single instance of each app keeps all tidier), also for Virtualbox, etc.... I have different keybindings to start certain apps with or without the launch script depending on the purpose/needs and I never use it for others. Be creative and you will love it.
Offline
Thanks for sharing, I guess this would work great with wbar as well?
Offline
It needs xdotool as well. Nice looking app.
Debian 12 Beardog, SoxDog and still a Conky 1.9er
Online
Never used wbar. If it works as a window it should be treated the same by the WM.
It needs xdotool as well
Thanks for pointing out, S11. Since both wmctrl and xdotool always live inside my systems I wasn't aware of it.
Offline
Although AFAIK, `xdotool` and `wmctrl` should both be present on a default BL install.
Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt «» BunsenLabs on DeviantArt
Offline
^I'm sure they do. I mentioned it since the script came from VSIDO and Snap pointed out that "It needs wmctrl." and in the script it clearly uses xdotool as well.
So we LabRats are covered, but are all visitors? Just trying to make sure Snap gets a home run.
@Snap
xdotool has been on my system ever since I started playing with mrpeachy's interactive conkys since those require both xdtool and wmctrl. I already had "wmctrl" as I use it to start conkys on various desktops.
Debian 12 Beardog, SoxDog and still a Conky 1.9er
Online
^ Do you know if they were added? last I installed Debian proper neither was installed by default.
@b-rex - it should prevent a second instance of wbar from starting, but I don't know about the focus and minimizing aspects of it.
If you do not want to run a script, you can also use something like:
wmctrl -a firefox || firefox
as a key binding. It will prevent a second incidence of the app from starting, and bring the currently running instance into focus. No minimizing.
Last edited by PackRat (2015-12-07 18:12:58)
You must unlearn what you have learned.
-- yoda
Offline
^I'm sure they do. I mentioned it since the script came from VSIDO and Snap pointed out that "It needs wmctrl." and in the script it clearly uses xdotool as well.
So we LabRats are covered, but are all visitors? Just trying to make sure Snap gets a home run.
.....
I've started adding a little bit of bash to all my scripts to test if required tools are installed. I've posted it here:
Script snippet to test if required tools exist
Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt «» BunsenLabs on DeviantArt
Offline
^ Do you know if they were added? last I installed Debian proper neither was installed by default....
They are dependencies of some of the bl- scripts, so I expect the iso/packages boys have it organised (but don't quote me on that, since that stuff is above my pay-grade )
Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt «» BunsenLabs on DeviantArt
Offline
I've started adding a little bit of bash to all my scripts to test if required tools are installed. I've posted it here:
Script snippet to test if required tools exist
Awesome! Thank you!
Offline
I hope you don't mind some comments on the bash
There are several unnecessary pipes which can be simplified (eg use pgrep, and parameter substitution), and use of frowned-upon command substitution.
Why backticks should generally be avoided is explained here
In general you really should only use the form $(), it's escaping-neutral, it's nestable, it's also POSIX.
After extensive tutoring by @johnraff and @xaos52 in recent months, I suggest....
#!/bin/bash
#.....
# there has to be at least one parameter, the name of the file to execute
if (( $# == 0 ));then
echo "Usage: $(basename $0) executable_name [parameters]"
exit 1
fi
BNAME=$(basename $1)
# test to see if program is already running
if [[ $(pgrep -a $BNAME) ]]; then
# means it must already be running
ACTIV_WIN=$(xdotool getactivewindow getwindowpid)
LAUNCH_WIN=$(pgrep $BNAME)
if [[ $ACTIV_WIN = $LAUNCH_WIN ]]; then
# launched app is currently in focus, so minimize
xdotool getactivewindow windowminimize
else
# launched app is not in focus, so raise and bring to focus
win=$(wmctrl -lx | grep $BNAME)
wmctrl -i -a ${win%% *}
fi
exit
else
# start it up
$*&
fi
exit 0
Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt «» BunsenLabs on DeviantArt
Offline
Here is what I would make of this:
#!/bin/bash
#.....
# there has to be at least one parameter, the name of the file to execute
if (( $# == 0 ));then
echo "Usage: $(basename $0) executable_name [parameters]"
exit 1
fi
launchee=$(basename "$1")
# test to see if program is already running
if [[ $(pgrep -a "$launchee") ]]; then
# means at least one launchee process must already be running
active_window_pid=$(xdotool getactivewindow getwindowpid)
launchee_pids=($(pgrep "$launchee"))
# is acitve_window_pid one of the already running launchee?
if [[ "${launchee_pids[@]}" =~ "*${active_window_pid}*" ]]; then
# launched app is currently in focus, so minimize
xdotool getactivewindow windowminimize
else
# launchee instance is not in focus, so raise and bring to focus
# which one do you bring into focus if there are many?
# First one is easiest
declare -a wins
while IFS= read -r; do
wins+=("$REPLY")
done < <(wmctrl -lx | grep "$launchee")
# printf '%s\n' "${wins[@]}"
wmctrl -i -a "${wins[0]%% *}"
fi
else
# start it up
"$@"&
fi
exit 0
Remarks:
As a general rule ( I know there are exceptions ) quote your variables.
Your script breaks when the launchee contains embedded spaces.
I know it is not wise to call your application 'my very own application', but you can do it, and your script should not break on it.
Your script should handle the situation where some launchee are already running.
Reserve all uppercase variables for variables you read from your environment, such as EUID, USER, HOME.
Your script should handle launchee with arguments, f.e.
launcher xterm -geometry 100x70+10+10
Hope you don't mind
Any remarks gratefully accepted
Last edited by xaos52 (2015-12-08 11:21:14)
Offline
@damo & doc
I hope you don't mind [...]
Me? I'm not the author. It was apparently borrowed by VastOne from some forum. As a launch addict i can only applaud and welcome your stress tests and improvements. Thanks, guys!
EDIT: The script was not "borrowed" by VastOne from the xfce forum. He's one of the authors and the OP starter.
Last edited by Snap (2015-12-09 07:57:11)
Offline
Reserve all uppercase variables for variables you read from your environment, such as EUID, USER, HOME
What is the reasoning behind this? Is it just to prevent possible clashes with env vars?
The learning never stops!
When this script is polished it could be a valuable addition to the BL arsenal
Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt «» BunsenLabs on DeviantArt
Offline
Offline
@damo
launchee iceweasel
Cannot convert argument to number.
@xaos52
launchee iceweasel
wmctrl: option requires an argument -- 'a'
Original version seems to work on all tested, but doesn't fully understand urxvt. Also makes my wbar look smarter.
Last edited by brontosaurusrex (2015-12-09 20:42:46)
Offline
@damo
launchee iceweasel
Cannot convert argument to number.
I can't say I did much testing - I was mainly concerned with improving some of the ugly bash code
Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt «» BunsenLabs on DeviantArt
Offline
Excellent! Saved.
...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )
Offline
Original version seems to work on all tested, but doesn't fully understand urxvt.
Yeah, you want to start something in a new urxvt tab, don't you? It's not a launch fault. It happens with or without it. I'm also struggling to make it work. That's one of the reason why I keep xfce4-terminal on board. You can start anything into a new tab instead of a new instance easily but haven't found a way for urxvt yet.
Offline
some of the ugly bash code
It might be ugly, but works flawless.
Offline