Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Mon 11 Dec 2017, 15:19
All times are UTC - 4
 Forum index » House Training » HOWTO ( Solutions )
shell, prevent to open multiple box
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [7 Posts]  
Author Message
fabrice_035

Joined: 28 Apr 2014
Posts: 446

PostPosted: Thu 21 Sep 2017, 13:39    Post subject:  shell, prevent to open multiple box  

hey,

It's simple tips i know , but rarely applied Shocked

Try with yassm-select (version 2.7), add this at top

Code:

#!/bin/bash
# (...)

present=`wmctrl -l | grep "YASSM v2.7"`
if [ "$present" != "" ] ; then
wmctrl -R "YASSM V2.7"
exit
fi

# (...)


Hidden windows showing in front.

Purpose another way ?

Think about that ? Rolling Eyes
Regard
Back to top
View user's profile Send private message 
Flash
Official Dog Handler


Joined: 04 May 2005
Posts: 12712
Location: Arizona USA

PostPosted: Thu 21 Sep 2017, 14:26    Post subject:  

Could you give us more of a description of what this does, what it is for?
Back to top
View user's profile Send private message 
fabrice_035

Joined: 28 Apr 2014
Posts: 446

PostPosted: Thu 21 Sep 2017, 15:03    Post subject:  

In my example, it's for place a always running program at front and take focus.

Before that, same program running several times.
Back to top
View user's profile Send private message 
Flash
Official Dog Handler


Joined: 04 May 2005
Posts: 12712
Location: Arizona USA

PostPosted: Thu 21 Sep 2017, 19:04    Post subject:  

If I understand you correctly, this will prevent more than one instance of the program from running?
Back to top
View user's profile Send private message 
musher0


Joined: 04 Jan 2009
Posts: 11252
Location: Gatineau (Qc), Canada

PostPosted: Thu 21 Sep 2017, 20:12    Post subject:  

Hello Flash (and fabrice)

See the wmctrl man page at https://linux.die.net/man/1/wmctrl
Code:
wmctrl -R [window]
brings that window in focus.

I never thought of using it, actually, but it can be quite useful for any
window hidden behind other windows.

If I can comment fabrice's code:
Code:

#!/bin/bash
# (...) # Probably the (c), GPL3 notice, maybe some strings, etc., here.

present=`wmctrl -l | grep "YASSM v2.7"`
# We check with wmctrl -i if we have a window called YASSM.
if [ "$present" != "" ] ; then # If we do
wmctrl -R "YASSM V2.7"  # we bring it in front
exit # and we exit the script
fi
# (...) # Otherwise we execute what's following here.


This bit of code is actually a "one-instance only" check.

If I can suggest an improvement, fabrice could replace the < exit > with an
< else > and push back the < fi > to the end, after the rest of the code. If
the first condition is satisfied, the part after the else will be skipped, and
the script will exit normally. There is no need to force the exit.
Code:
#!/bin/bash
# (...) # Probably the (c), GPL3 notice, maybe some strings, etc., here.

present=`wmctrl -l | grep "YASSM v2.7"`
# We check with wmctrl -i if we have a window called YASSM.
if [ "$present" != "" ] ; then # If we do
wmctrl -R "YASSM V2.7"  # we bring it in front
else # <<=- Change
(...) # The rest of the code
fi

IHTH

_________________
musher0
~~~~~~~~~~
"Logical entities must not be multiplied beyond necessity." | |
« Il ne faut pas multiplier les entités logiques sans nécessité. » (Ockham)
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1397
Location: Japan

PostPosted: Thu 21 Sep 2017, 23:48    Post subject: Re: shell, prevent to open multiple box  

fabrice_035 wrote:
Code:
present=`wmctrl -l | grep "YASSM v2.7"`
if [ "$present" != "" ] ; then
wmctrl -R "YASSM V2.7"
exit
fi

Keep it simple:
Code:
wmctrl -R "YASSM V2.7" && exit


Flash wrote:
If I understand you correctly, this will prevent more than one instance of the program from running?

Hmmm...that's what the thread title implies but it's not what it does. If multiple instances are already running, the code grabs the first window with "YASSM V2.7" in the title (actually the oldest of the bunch) and moves it to the current desktop.

To prevent multiple instances I use wmctrl when starting programs from tray buttons. First wmctrl looks for any already existing program window and when it finds one it moves it to my present desktop, if it fails, i.e. if the program is not already running, the code starts the program.
Example for galculator:
Code:
wmctrl -R galculator || /usr/bin/galculator


It's also possible to put this code directly into a desktop icon:
Move_here_else_open.png
 Description   
 Filesize   15.11 KB
 Viewed   85 Time(s)

Move_here_else_open.png

Back to top
View user's profile Send private message 
fabrice_035

Joined: 28 Apr 2014
Posts: 446

PostPosted: Fri 22 Sep 2017, 04:09    Post subject:  

Quote:

@MochiMoppe , It's also possible to put this code directly into a desktop icon


Fabulous Shocked But lose default icon, need to restore after.

[Edit] But no good idea, because redefine icon with Set Icon menu option is for `/bin/bash` , so all shortcuts have same icon Crying or Very sad
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [7 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » House Training » HOWTO ( Solutions )
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0917s ][ Queries: 12 (0.0068s) ][ GZIP on ]