Xfce Forum

Sub domains
 

You are not logged in.

#26 2012-02-08 04:38:35

Vastone
Member
Registered: 2011-08-03
Posts: 50

Re: [Solved] 4.8 Panel question/suggestion

Hi ToZ

Yes to the logic.  This would handle anything in a panel or launcher. 

I understand wmctrl -k does close everything and from a launcher standpoint, that is fine.  Not the best but not the worst either ... smile 

I have spent the last couple of hours trying to find he xdotool and/or wmctrl function to minimize an app and have not found if it is even possible.

Offline

#27 2012-02-08 15:13:51

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,948

Re: [Solved] 4.8 Panel question/suggestion

Try this (only tested with 2 apps):

#!/bin/bash

# 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

# test to see if program is already running
if [ "`wmctrl -lx | tr -s ' ' | cut -d' ' -f1-3 | grep -i $1`" ]; then 
	# means it must already be running
	ACTIV_WIN=$(xdotool getactivewindow getwindowpid)
	LAUNCH_WIN=$(pidof $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 $1 | cut -d' ' -f1`
		do
		    wmctrl -i -a $win
		done
	fi
	exit

else
	# start it up
	$*&
	exit
fi

exit 0

Last edited by ToZ (2012-02-08 15:15:01)


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#28 2012-02-08 16:49:57

Vastone
Member
Registered: 2011-08-03
Posts: 50

Re: [Solved] 4.8 Panel question/suggestion

Morning ToZ

Thanks for looking into and helping with this! smile

It works on most apps.  It partially works on Iceweasel that I have running from a .desktop file.  If there are no focused Windows, clicking on the Iceweasel Icon does nothing at all.  If there is a different focused Window then clicking the icon does work, but it never minimizes when clicking the Iceweasel icon

Nearly the same thing happens with my music app gmuscibrowser also running as a .desktop file.  The only difference is clicking the icon will always maximize gmb but will never minimize it

I thought it might be an issue from within the .desktop files but it is not.  These two apps are the only two I am using that the Window Title changes to show what is on the app when running

On xfce4-terminal, file manager and Xchat it works perfectly.  These three load the same way with a .desktop file

Last edited by Vastone (2012-02-08 17:03:02)

Offline

#29 2012-02-08 17:08:23

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,948

Re: [Solved] 4.8 Panel question/suggestion

Turns out that the gmusicbrowser app is a script that is run via perl. I had to change the pidof command to also return the pid of scripts being run (-x parameter). I don't have iceweasel installed to test, but this version now works with gmusicbrowser (also tested with firefox, gcalctool & abiword)

#!/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

# test to see if program is already running
if [ "`wmctrl -lx | tr -s ' ' | cut -d' ' -f1-3 | grep -i $1`" ]; then 
	# means it must already be running
	ACTIV_WIN=$(xdotool getactivewindow getwindowpid)
	LAUNCH_WIN=$(pidof -x $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 $1 | cut -d' ' -f1`
		do
		    wmctrl -i -a $win
		done
	fi
	exit

else
	# start it up
	$*&
fi

exit 0

EDIT: Also works with gimp.

Last edited by ToZ (2012-02-08 17:18:40)


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#30 2012-02-08 17:24:47

Vastone
Member
Registered: 2011-08-03
Posts: 50

Re: [Solved] 4.8 Panel question/suggestion

^ It is interesting that it works with firefox for you and not iceweasel for me.  As you know, iceweasel is just a rebranded ff

I made the changes and but I am not seeing it do anything different with GMB. The difference I see is that I am running gmb from a specific path and gmusicbrowser.pl (the git version) from the .desktop file.

Offline

#31 2012-02-08 18:28:32

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,948

Re: [Solved] 4.8 Panel question/suggestion

What does:

ps -ef | grep -i gmusicbrowser

return?

and

ps -ef | grep -i iceweasel

return?

Last edited by ToZ (2012-02-08 18:29:49)


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#32 2012-02-08 18:31:48

Vastone
Member
Registered: 2011-08-03
Posts: 50

Re: [Solved] 4.8 Panel question/suggestion

vastone   3427     1  4 11:44 ?        00:01:58 /usr/bin/perl /home/vastone/gmusicbrowser/gmusicbrowser.pl
vastone   2800     1 12 11:43 ?        00:06:08 /usr/lib/iceweasel/firefox-bin

Offline

#33 2012-02-08 19:15:11

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,948

Re: [Solved] 4.8 Panel question/suggestion

Okay. The original script only worked with one-word executables that existed in the system path. I've updated the script to take care of non-path executables. Tested to work on gmusicbrowser from git. The command I used to test it was:

launch /home/toz/Downloads/squentin-gmusicbrowser-92f0302/gmusicbrowser.pl

Here is the updated script:

#!/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 "$1" | 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

Now about iceweasel. As you can see, its just running firefox-bin (even though its called iceweasel). This is going to make it difficult.

What command is used to start iceweasel?

Last edited by ToZ (2012-02-08 19:15:57)


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#34 2012-02-08 19:20:14

Vastone
Member
Registered: 2011-08-03
Posts: 50

Re: [Solved] 4.8 Panel question/suggestion

Awesome - that patched worked for both!!

Every one of the launchers is now acting as it should..

Very nice work! 

If you have a paypal setup I can send you some coin for this!

I really appreciate this ... smile

Offline

#35 2012-02-08 19:24:45

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,948

Re: [Solved] 4.8 Panel question/suggestion

No worries, I enjoy the challenge. Keeps me sharp (and out of trouble).

I did however find one error in the script that may or may not be a bug (line 22, $1 instead of $BNAME). Here is the script updated to fix that. Give it a try and see if it still works (looks good here, but can't test iceweasel).

#!/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

Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#36 2012-02-08 19:29:19

Vastone
Member
Registered: 2011-08-03
Posts: 50

Re: [Solved] 4.8 Panel question/suggestion

I did apply it and test it and it works just the same.

Iceweasel and every other launcher is working

Glad I can help in keeping you out of trouble! smile

Nice job mate!

Offline

#37 2019-01-10 06:00:45

1421
Member
Registered: 2019-01-10
Posts: 9

Re: [Solved] 4.8 Panel question/suggestion

sorry im noob how do i use this if i want this for firefox what does it look like?
i do this but nothing happens when i click it

3. Create a new launcher (pcmanfm for demo purposes):
Right-click Panel->Panel->Add New Items,
select "Launcher" and click "Add" (new launcher appears on panel), click "Close"
Right-click the new launcher icon->Properties
click on "Add new empty item" button (4th button down on right side)
set: Name = pcmanfm
       Comment = <whatever_you_want>
       Command = /home/user/launcher pcmanfm
       Select an icon
       Check "Use startup notification"
Click "Create

do i need firefox in the script somewhere and what about the parameter?


ToZ wrote:

No worries, I enjoy the challenge. Keeps me sharp (and out of trouble).

I did however find one error in the script that may or may not be a bug (line 22, $1 instead of $BNAME). Here is the script updated to fix that. Give it a try and see if it still works (looks good here, but can't test iceweasel).

#!/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

Offline

#38 2019-01-10 12:03:39

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,948

Re: [Solved] 4.8 Panel question/suggestion

1421 wrote:

sorry im noob how do i use this if i want this for firefox what does it look like?
...
do i need firefox in the script somewhere and what about the parameter?

You don't need firefox in the script, just in the launcher. Change the launcher name to "Firefox" and the command to "/path/to/your/script firefox", where "/path/to/your/script is the filesystem path to where te script resides. Also make sure the script is executable "chmod +x /path/to/your/script".

Welcome to the forums.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#39 2019-01-10 19:04:21

1421
Member
Registered: 2019-01-10
Posts: 9

Re: [Solved] 4.8 Panel question/suggestion

i thought it was going to merge with the launcher it also is not possible to click 2 times for more windows

basically i want to not see the launcher icon if the program is in use

Last edited by 1421 (2019-01-10 19:09:32)

Offline

#40 2019-01-10 21:07:00

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,948

Re: [Solved] 4.8 Panel question/suggestion

1421 wrote:

basically i want to not see the launcher icon if the program is in use

xfce4-panel can't do this. Look to see if your distro still packages xfce4-taskbar-plugin. If not, you'll have to use something like plank.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#41 2019-01-10 22:44:03

1421
Member
Registered: 2019-01-10
Posts: 9

Re: [Solved] 4.8 Panel question/suggestion

ToZ wrote:
1421 wrote:

basically i want to not see the launcher icon if the program is in use

xfce4-panel can't do this. Look to see if your distro still packages xfce4-taskbar-plugin. If not, you'll have to use something like plank.

ok i guess il stick with the way it is then because i dont like plank much thanks

Offline

#42 2020-09-08 09:09:08

julian
Member
Registered: 2020-09-07
Posts: 31

Re: [Solved] 4.8 Panel question/suggestion

Hi ToZ,

This is great! Unfortunately it doesn't appear to be working 9 years later smile

Steps to reproduce

Added the above script to a path with a loving filename /home/<name>/org.xfce.unintergratedLauncherFocuser.sh. Allowed the script to be executed (via Right-click > Properties > Permissions so a layman feels more comfortable) so that the permissions are (according to the ls command) -rwxr-xr-x <name> <name>. In the launcher itself I simply add the script path before the usual app command in the Command field. I tried it with two apps, AisleRiot Solitare. So with command in launcher being sol, command becomes:

/home/<name>/org.xfce.unintergratedLauncherFocuser.sh sol

and GIMP, with command in launcher, gimp2.0 %U, becomes:

/home/<name>/org.xfce.unintergratedLauncherFocuser.sh gimp2.0 %U

Unfortunately the behavior seems to be unchanged. That is, AisleRiot loads a new window and new game and GIMP does not minimise (launching GIMP doesn't open a new instance of the program, it restores the program (with side-effects, it seems)).

I tried refreshing the panel with command xfce4-panel -r to no effect

Follow-up question

I'm going to ask a question and you'll know why immediately. Would your script be able to somehow block the Window Buttons component from getting/keeping a "reference" to the program? wink

Last edited by julian (2020-09-08 10:51:47)


PGP: 4198 58E4 F9E8 AC05 FDEA A303 F083 6D52 5A2D 8356

Find my email where you get good encryption keys.

Offline

#43 2020-09-08 10:52:26

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,948

Re: [Solved] 4.8 Panel question/suggestion

I just tested it and the script still works. Make sure that you have xdotool and wmctrl installed.

Regarding the follow-up question, you could add:

sleep 1 && wmctrl -r :ACTIVE: -b add,skip_taskbar

somewhere in the code to do this. It would depend on what point you would want it to happen. If its when the app is first started, then add it in right after:

	# start it up
	$*&

Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#44 2020-09-08 18:48:12

julian
Member
Registered: 2020-09-07
Posts: 31

Re: [Solved] 4.8 Panel question/suggestion

Thanks for the install tip. I really should have just tried running it in the terminal, lol, yes!!

It's working now and your new addition (above) is gooood, but we are not quite out of the woods yet. Some apps take a few seconds to show in the component, like GIMP.

It seems like we need to wait for the program to be added before we act. Perhaps listening for a modification to a file or the existence of new file?

Last edited by julian (2020-09-08 18:50:55)


PGP: 4198 58E4 F9E8 AC05 FDEA A303 F083 6D52 5A2D 8356

Find my email where you get good encryption keys.

Offline

#45 2020-09-08 23:27:14

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,948

Re: [Solved] 4.8 Panel question/suggestion

Try this:

# start it up
	$*&

while ! wmctrl -lx | grep $BNAME ; do sleep .1s ; done
wmctrl -r :ACTIVE: -b add,skip_taskbar

Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#46 2020-09-09 00:41:21

julian
Member
Registered: 2020-09-07
Posts: 31

Re: [Solved] 4.8 Panel question/suggestion

Total Splendid-ness, ToZ!

It might not take focus away from Solitaire, and GIMP must do something weird behind the scenes to generate difference processes perhaps, but thinking about it I don't mind GIMP in the Window Buttons. That icon looks different (it shows the users artwork) and acts different, and there's nothing buggy about it. The few other things I'm setting up as launchers seem perfect.

BIG KUDOS! big_smile


PGP: 4198 58E4 F9E8 AC05 FDEA A303 F083 6D52 5A2D 8356

Find my email where you get good encryption keys.

Offline

Board footer

Powered by FluxBB