Xfce Forum

Sub domains
 

You are not logged in.

#1 2011-08-03 03:22:53

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

[Solved] 4.8 Panel question/suggestion

Is it possible with the 4.8 panel to assign a launcher a function to only open an existing open app?

In cairo-dock this is known as "grab" the window that the dock launcher is assigned..

Simply, if I have firefox open and click the launcher that I have created for firefox again, that it open the existing open FF and not a new one..

If I could get this function to work, I could completely remove cairo-dock...

Thanks for the greatness of xfce!!!!

Offline

#2 2011-08-03 04:47:37

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

Re: [Solved] 4.8 Panel question/suggestion

Not sure if the functionality exists in xfce, but I use wmctrl and a helper script to start a program if its not running and/or raise it to the front, for a couple of apps (namely decibel-audio-player and chromium-browser).  I create a copy of this helper script for each app that I want to manage this way and assign the helper script to the launcher. Here is the code:

#!/bin/bash

# set the name of the program to process
PROGNAME="decibel-audio-player"

# if the program is not running, then start it
[ "`ps -ef | grep $PROGNAME | grep -v grep`" ] || ($PROGNAME &)

# get the pid
PROG_PID=`ps -ef | grep $PROGNAME | grep -v grep | head -1 | tr -s ' ' | cut -d' ' -f2`

# get the window title
WINTITLE=`wmctrl -p -l | grep $PROG_PID | cut -d' ' -f8-`

# bring the window to the front
wmctrl -a "$WINTITLE"

exit 0

Hopefully this can suffice as a workaround. YMMV.


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

#3 2011-08-03 04:56:34

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

Re: [Solved] 4.8 Panel question/suggestion

ToZ wrote:

Not sure if the functionality exists in xfce, but I use wmctrl and a helper script to start a program if its not running and/or raise it to the front, for a couple of apps (namely decibel-audio-player and chromium-browser).  I create a copy of this helper script for each app that I want to manage this way and assign the helper script to the launcher. Here is the code:

#!/bin/bash

# set the name of the program to process
PROGNAME="decibel-audio-player"

# if the program is not running, then start it
[ "`ps -ef | grep $PROGNAME | grep -v grep`" ] || ($PROGNAME &)

# get the pid
PROG_PID=`ps -ef | grep $PROGNAME | grep -v grep | head -1 | tr -s ' ' | cut -d' ' -f2`

# get the window title
WINTITLE=`wmctrl -p -l | grep $PROG_PID | cut -d' ' -f8-`

# bring the window to the front
wmctrl -a "$WINTITLE"

exit 0

Hopefully this can suffice as a workaround. YMMV.

Perfection!!!  My mileage just expanded tenfold!!!

Very little overhead with wmctrl... Just what I was looking for...

Thanks so much ToZ!

Offline

#4 2011-08-03 06:23:27

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

Re: [Solved] 4.8 Panel question/suggestion

@ ToZ

How would you handle apps like pcmanfm or terminator that does not use the app name in the WINTITLE? 

pcmanfm uses the current directory and terminator uses loginid@hostname

Or for example, if you needed to use a variable...

terminator -T terminator

forces terminator to use terminator as the window title, but the script does not seem to allow for a variable...

I am googling as well for the answers...

2nd Edit - Resolved the terminator issue by replacing the following in .bashrc 

case "$TERM" in
xterm*|rxvt*)
    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"'
    ;;
*)
    ;;
esac

with

APPNAME=$(basename $(cat /proc/$PPID/cmdline))
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~} $APPNAME\007"'
    ;;
*)
    ;;
esac

Thanks...

Last edited by Vastone (2011-08-03 07:53:09)

Offline

#5 2011-08-03 15:21:13

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

Re: [Solved] 4.8 Panel question/suggestion

Ok. Changed the script around a bit. First, I made the script take a parameter (the executable name), so that you only need one launcher script. Usage is like:

launcher pcmanfm

I also found that it wasn't a good idea to grep on ps-ef (especially in a multi-user environment) and it was better to grep on class name using only the wmctrl-managed windows (wmctrl -lx) so to avoid issues where the same phrase is on multiple windows (ie. pcmanfm and firefox open to a page about pcmanfm) and focus only on the current graphical login environment (hope that makes sense). Anyways, here is the new code that works with pcmanfm and a bunch of others that I tested:

#!/bin/bash

if [ $# -ne 1 ]
then
  echo "Usage: `basename $0` {executable_name}"
  exit 1
fi

# if the program is not running (being managed by wmctrl), then start it
[ "`wmctrl -lx | grep -i $1`" ] || (($1&) && (sleep 1))

# now let's make sure it's raised and brought to the front
wmctrl -i -a "`wmctrl -lx | tr -s ' ' | cut -d' ' -f1-3 | grep -i $1 | cut -d' ' -f1 | head -1`"

exit 0

The next thing to work on is to bring to the front all instances of a given window (ie - if you have 3 open pcmanfm windows, bring them all to the front).

Last edited by ToZ (2011-08-03 15:23:48)


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

#6 2011-08-03 15:32:08

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

Re: [Solved] 4.8 Panel question/suggestion

ToZ wrote:

Ok. Changed the script around a bit. First, I made the script take a parameter (the executable name), so that you only need one launcher script. Usage is like:

launcher pcmanfm

I also found that it wasn't a good idea to grep on ps-ef (especially in a multi-user environment) and it was better to grep on class name using only the wmctrl-managed windows (wmctrl -lx) so to avoid issues where the same phrase is on multiple windows (ie. pcmanfm and firefox open to a page about pcmanfm) and focus only on the current graphical login environment (hope that makes sense). Anyways, here is the new code that works with pcmanfm and a bunch of others that I tested:

#!/bin/bash

if [ $# -ne 1 ]
then
  echo "Usage: `basename $0` {executable_name}"
  exit 1
fi

# if the program is not running (being managed by wmctrl), then start it
[ "`wmctrl -lx | grep -i $1`" ] || (($1&) && (sleep 1))

# now let's make sure it's raised and brought to the front
wmctrl -i -a "`wmctrl -lx | tr -s ' ' | cut -d' ' -f1-3 | grep -i $1 | cut -d' ' -f1 | head -1`"

exit 0

The next thing to work on is to bring to the front all instances of a given window (ie - if you have 3 open pcmanfm windows, bring them all to the front).

Great work ToZ..  I stayed up half the night reading about wmctrl and was going to ask you about the -lx parameter and you had already resolved it...

In your example, are you saying that

launcher pcmanfm

is what you run from within the XFCE panel Command line?

I am not quite sure where to start this new script from  ...

Thanks ...

Offline

#7 2011-08-03 15:32:32

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

Re: [Solved] 4.8 Panel question/suggestion

And, in case you're interested, here is the code if you want to raise and bring forward all windows of the same class/executable (ie. if you have multiple pcmanfm windows open, they will all be raised and brought to the front)

#!/bin/bash

if [ $# -ne 1 ]
then
  echo "Usage: `basename $0` {executable_name}"
  exit 1
fi

# if the program is not running (being managed by wmctrl), then start it
[ "`wmctrl -lx | grep -i $1`" ] || (($1&) && (sleep 1))

# now let's make sure all related windows are raised and brought to the front
for win in `wmctrl -lx | tr -s ' ' | cut -d' ' -f1-3 | grep -i $1 | cut -d' ' -f1`
do
    wmctrl -i -a $win
done

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

#8 2011-08-03 15:35:31

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

Re: [Solved] 4.8 Panel question/suggestion

When you create the launcher (or change the properties for an existing launcher), for the applications that you want this script to manage, type in as the command:

/path/to/launcher progname

Something like:

/home/user/launcher firefox

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

#9 2011-08-03 15:45:27

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

Re: [Solved] 4.8 Panel question/suggestion

More detailed instructions (from a terminal window):

1. Create the launcher file:

mousepad ~/launcher

paste in the contents of the script and save the file.

2. Make the script executable:

chmod +x ~/launcher

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

4. Enjoy.


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

#10 2011-08-03 15:47:27

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

Re: [Solved] 4.8 Panel question/suggestion

ToZ wrote:

When you create the launcher (or change the properties for an existing launcher), for the applications that you want this script to manage, type in as the command:

/path/to/launcher progname

Something like:

/home/user/launcher firefox

Works perfectly...

I saved this in

/home/my login name/bin/launcher

and do not need to worry about the path when executing from XFCE Panel properties..

Thank you so much!!!

Last edited by Vastone (2011-08-03 16:00:45)

Offline

#11 2011-08-03 15:55:44

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

Re: [Solved] 4.8 Panel question/suggestion

ToZ wrote:

More detailed instructions (from a terminal window):

1. Create the launcher file:

mousepad ~/launcher

paste in the contents of the script and save the file.

2. Make the script executable:

chmod +x ~/launcher

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

4. Enjoy.

This works perfectly... 

This will become a nice How-To

Great job ToZ!

Last edited by Vastone (2011-08-03 16:18:04)

Offline

#12 2011-08-03 17:01:05

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

Re: [Solved] 4.8 Panel question/suggestion

Offline

#13 2011-08-03 21:19:58

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

Re: [Solved] 4.8 Panel question/suggestion

@ ToZ

Another challenge...

Do you think there would be a way to use launcher with .desktop files?

This script works.. 

http://www.humbug.in/2011/single-keyboa … plication/

by putting find_app.sh "terminator" in the

Exec=    section of

/home/my login name/bin/terminator.desktop file..

Yours is cleaner so I was curious as to what your thoughts would be on this..

Again I really appreciate it...

Offline

#14 2011-08-04 02:13:30

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

Re: [Solved] 4.8 Panel question/suggestion

I guess you could copy the launcher script to /usr/local/bin so that it is available for all users. Then edit all of the .desktop files in /usr/share/applications and ~/.local/share/applications so that the exec section is preceeded by launcher like:

launcher mousepad

A couple of problems/issues:
1. you would have to manually edit all of the .desktop files (tedious)
2. some of the .desktop files have parameters to the main executable (ie. mousepad.desktop -> Exec=mousepad %f). This would have to be accounted for with some extra code (doable).

(cracks open a beer and thinks.....)

Ok. If you don't mind manually editing all of the .desktop files, try this:

gksudo mousepad /usr/local/bin/launch

with this content:

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

# if the program is not running (being managed by wmctrl), then start it
[ "`wmctrl -lx | grep -i $1`" ] || (($*&) && (sleep 1))

# now let's make sure all related windows are raised and brought to the front
for win in `wmctrl -lx | tr -s ' ' | cut -d' ' -f1-3 | grep -i $1 | cut -d' ' -f1`
do
    wmctrl -i -a $win
done

exit 0

and make the file executable:

sudo chmod +x /usr/local/bin/launch

Then edit all of your .desktop files replacing the string "Exec=" with "Exec=launch ". (This part is clumsy and tedious but I can't think of an easier way to do it - short of changing the xfce code itself.)


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

#15 2011-08-04 03:07:29

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

Re: [Solved] 4.8 Panel question/suggestion

The last part     "Exec=launch "

Not sure what you meant there...

Exec=launch "xchat"

or

Exec="launch xchat"

May just be a typo...

This is how I was doing it with that other find_app.sh script..

I am trying this in tint2 and it allows you within the config to specify the .desktop file

in this case using xchat, I have xchat.desktop in my ~/.local/bin directory and specify it in the tint2 config file as such

launcher_item_app = /home/vastone/bin/xchat.desktop

Which is the only way tint2 will handle a launcher...

In any event, I have tried

Exec=launch "xchat"  (in my ~/.local/bin/xchat.desktop file)

without any success ...

I am sure it is user fault/error...  But even at a command line I cannot get launch xchat to work

Thanks

Offline

#16 2011-08-04 03:49:22

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

Re: [Solved] 4.8 Panel question/suggestion

Vastone wrote:

The last part     "Exec=launch "

Not sure what you meant there...

Exec=launch "xchat"

or

Exec="launch xchat"

May just be a typo...

This is how I was doing it with that other find_app.sh script..

I am trying this in tint2 and it allows you within the config to specify the .desktop file

in this case using xchat, I have xchat.desktop in my ~/.local/bin directory and specify it in the tint2 config file as such

launcher_item_app = /home/vastone/bin/xchat.desktop

Which is the only way tint2 will handle a launcher...

In any event, I have tried

Exec=launch "xchat"  (in my ~/.local/bin/xchat.desktop file)

without any success ...

The line should read: Exec=launch xchat

I am sure it is user fault/error...  But even at a command line I cannot get launch xchat to work

Thanks

What error message are you getting? I've got it working here.


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

#17 2011-08-04 04:07:57

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

Re: [Solved] 4.8 Panel question/suggestion

I guess I was not patient enough ToZ..   

I did not change anything but after seeing your reply I retried everything and it is working perfectly now...  Both from cli and from tint2 and xfce-panel

Thank you for the time and effort on this...  It gives me and several users choices...

Offline

#18 2011-08-04 05:02:12

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

Re: [Solved] 4.8 Panel question/suggestion

I figured out why some of the apps were not launching..  as I told you I saw it first with xchat and then it went away..

Next I tried pcmanfm and the same thing was happening..  where the icon would not launch and also launch pcmanfm from cli did not work

I had noticed I still had gedit open with the files for pcmanfm.desktop open...

I closed gedit and relaunched both from cli and the icon and it worked...

I knew I was not making a ridiculously stupid error and I have not had enough beers (yet) ...  but found the issue and that makes it worth it..

The problem is, the launcher was working each and every time...  from cli it gave no error message at all...

Offline

#19 2011-08-04 06:24:50

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

Re: [Solved] 4.8 Panel question/suggestion

OK I see. Found the bug. It wasn't starting xchat because gedit had the word "xchat" in its title (as you were editing the xchat.desktop file). Try this version instead (small change to line 11:

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

# if the program is not running (being managed by wmctrl), then start it
[ "`wmctrl -lx | tr -s ' ' | cut -d' ' -f1-3 | grep -i $1`" ] || (($*&) && (sleep 1))

# now let's make sure all related windows are raised and brought to the front
for win in `wmctrl -lx | tr -s ' ' | cut -d' ' -f1-3 | grep -i $1 | cut -d' ' -f1`
do
    wmctrl -i -a $win
done

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

#20 2011-08-04 06:33:00

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

Re: [Solved] 4.8 Panel question/suggestion

That solved it...

I opened both instances of xchat and pcmanfm in gedit and using both cli and the panel to launch now works

Thank you!

Offline

#21 2011-08-05 21:09:13

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

Re: [Solved] 4.8 Panel question/suggestion

@ ToZ

I created a How-To over on #! highlighting all of this...

http://crunchbanglinux.org/forums/post/136078/#p136078

Offline

#22 2011-08-05 21:20:36

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

Re: [Solved] 4.8 Panel question/suggestion

Cool.
Well written.


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

#23 2011-08-05 23:47:09

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

Re: [Solved] 4.8 Panel question/suggestion

Thank you!

Offline

#24 2012-02-08 00:09:32

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

Re: [Solved] 4.8 Panel question/suggestion

@ ToZ

I have found that

wmctrl -k on

minimizes everything running.  This is not a perfect fix for minimizing a single raised app using the launch bash code but does work.

How would you implement this into the bash so that if app is found running and raised it would then run wmctrl -k on and minimize everything?

Thanks

Offline

#25 2012-02-08 04:32:03

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

Re: [Solved] 4.8 Panel question/suggestion

Let me see if I understand the logic.

Is program running?
  - No = start program & give focus
  - Yes =
     - Is program focused?
        - Yes = minimize app
        - No = give app focus

Unfortunately, wmctrl -k is an all or nothing command. If my understanding above is correct, we would need to use a tool such as xdotool to selectively minimize an app. The complication would be aligning wmctrl window ids with xdotool window ids.


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

Board footer

Powered by FluxBB