Page 1 of 1

About yad [SOLVED]

Posted: Sat 14 Sep 2013, 14:29
by Argolance
Bonjour,
2 questions about yad:
  • - Is it possible to get icons inside a yad right click menu? If yes, how?
    - How to get the ID of a specific yad process? For example: I would like the "good" one to be "killed" if several are running simultaneously?
Thank you for your attention.

Cordialement.

Yad notification

Posted: Sat 14 Sep 2013, 17:57
by matiasbatero
Yes, it's possible.

Check my example:

Code: Select all

#!/bin/bash

mkfifo /tmp/01
exec 3<> /tmp/01

yad --notification --kill-parent --listen <&3 &

title="<b><big>✔</big> Testing notification                              </b>"
text="<i>Using HTML markup</i>"
add_2="

Posted: Sat 14 Sep 2013, 21:25
by Argolance
Bonsoir matiasbatero,
Thank you for replying!
Concerning text markup, I had no difficulties to get expected results (please see picture below!)
:D Great!
On the other hand, I couldn't get icons inside the right click menu which looks like this (please see picture below!):

Code: Select all

echo "menu:$REFRESH_TEXT!bash -c REFRESH_TRAY||$EXIT_TEXT!bash -c CLOSE_QUIT" >&3
More (fortunately that I had saved my work before testing 8) ), when I left clicked on the system tray icon of the running script you wrote above, PC rebooted instantaneously :shock:
So, those who want to test this script should be very careful: pleeeeaaaase, do not left click on the notification icon if you have something which is cooking lovingly in the oven.
Just right click!


Don't know exactly why...
To get the pid, you can do this:

Code:
yad --options &
PID=$!
Sorry but I don't know how to use this inside the script I am working on :oops: I must admit Yad is quite new for me.

[EDIT]: After some tests, this is ok for the PID :D

Cordialement.

Posted: Sat 14 Sep 2013, 21:37
by Karl Godt
Have not tested anything and not using yad , but


ME_PID=$$

command &
zPID0=$!

KILL_PID=`ps | grep "${0##*/}" | grep -w "$zPID0"`
kill -9 $KILL_PID

probably could do it -- actually Barry uses $! quite a while in his scripts as in
/usr/sbin/bootmanager

yeslist_func() {
#choose extra modules to load at bootup.
yaf-splash -font "8x16" -outline 0 -margin 4 -bg orange -text "Please wait, processing..." &
X1PID=$!

*
Don't confuse "$!" with "!$" !

Posted: Sun 15 Sep 2013, 10:39
by Argolance
Thank you Karl! :D

Posted: Sun 15 Sep 2013, 17:37
by Argolance
Bonjour,
I played and had fun with yad...
1)
On the other hand, I couldn't get icons inside the right click menu which looks like this (please see picture below!):
Code:
echo "menu:$REFRESH_TEXT!bash -c REFRESH_TRAY||$EXIT_TEXT!bash -c CLOSE_QUIT" >&3
I was running an old version of yad (0.12.1). After compiling/installing the latest version (0.23.0), I get the icons in the right click menu! :D
:?: @matiasbatero
But: This works using customized icons (ex: usr/share/pixmaps/mycon.png), and only with some gtk icons. gtk-preference, for example, is correctly displayed, but not the icons gtk-quit, gtk-close... :(
How could this be solved?

2)
More (fortunately that I had saved my work before testing Cool ), when I left clicked on the system tray icon of the running script you wrote above, PC rebooted instantaneously Shocked
So, those who want to test this script should be very careful: pleeeeaaaase, do not left click on the notification icon if you have something which is cooking lovingly in the oven.
Just right click!
I was running this script directly in terminal, so the option "--kill-parent" was the reason of the problem. Either you test it in terminal without this option, or you use it inside a bash script. The option will kill the bash script while exiting the yad system tray and nothing happens while left clicking on the yad system tray icon (LEFT_CLICK. has to be defined) :D

Hope this can be helpful!

Cordialement.

Posted: Mon 16 Sep 2013, 03:58
by matiasbatero
Hi!

You can use only this stock gtk-icons, this is the list: http://developer.gnome.org/gtk2/2.24/gt ... Items.html

Also you can use icons using app names. Like: leafpad thunar rox

Here, gtk-close, gtk-quit works! and it's Yad 0.23

This line, works here:

Code: Select all

echo "menu:Eject /dev/sr0!bash -c eject /dev/sr0!gtk-cdrom|Exit!quit!gtk-close" >&3
It's strange that some icons work and others not.

1) Check if you have that icons, or symbolic links.
2) I can't remember if works, but i read in some time, that one can add Eviroment Variables with icon paths. Maybe this can help you if some configuration file is missing..

Posted: Mon 16 Sep 2013, 04:06
by matiasbatero
TIP:

If you want dynamic icon menu refreshing. Like.. Loading states, Copy status, anyway.. a notification with a progress indicator for example.

You can check my program, i wrote a bash function with a nice trick, that works very well. You can use to add more functionality or "stetic purposes"

http://murga-linux.com/puppy/viewtopic.php?t=87856

Screnshot (icon progress)
Image

Regards!
Matías Gastón.[/code]

Posted: Mon 16 Sep 2013, 11:06
by Karl Godt
--kill-parent
killed PID Nr 1 - literally init , that led to immediate reboot .

Posted: Wed 09 Oct 2013, 20:21
by Argolance
Bonsoir,

Code: Select all

	## Function kill yad process
	function KillYad(){
		echo "`ps | grep yad`" > $TEMP_DIR/yad_pid_tmp1
		grep POSou $TEMP_DIR/yad_pid_tmp1 > $TEMP_DIR/yad_pid_tmp2
		sed -i 's/^\s*//' $TEMP_DIR/yad_pid_tmp2
		cut -d" " -f 1 $TEMP_DIR/yad_pid_tmp2 > $TEMP_DIR/yad_pid
		YAD_PID="`cat $TEMP_DIR/yad_pid`"
		kill -15 $YAD_PID
	} # End of function
*POSou: pattern.
.... don't know if it is "beautiful" code lines, but it works!

Thanks!

Cordialement.

Posted: Thu 10 Oct 2013, 02:58
by Karl Godt
use
grep -w PATTERN
if
pattern contains no spaces or puncts .
Without -w option it would grab everything that contains the pattern .
For example if the pattern would be "1000" it would grab 1000, 11000, 21000, 31000 .

Code: Select all

kill_yad(){
PidWanted=`ps-FULL h -o pid,args | grep yad | awk '{print $1}' | grep -w "$1"`
[ "$PidWanted" ] || return 0
ps-FULL -p $PidWanted && { kill -15 $PidWanted && echo "Killed $1 ." || echo "Killing failed."; } || echo "Pid '$1' seems already gone."
}

Posted: Thu 10 Oct 2013, 14:58
by Argolance
Thank you!
This seems complex to me! :oops:
Sorry if my question is silly, but where is the pattern in these code lines (in my case "POSou, which is a part of the name of the png icon notification tray)? I mean, if there are several yad apps running at the same time, what could distinguish the one I have to kill from the others?

Code: Select all

15521 root       0:00 yad --notification --auto-kill --listen --no-middle --image=/usr/local/lib/X11/mini-icons/POSou_no-updates.png --text= <b>ToOpPy EST À JOUR! </b> -------------------------------------  Clic gauche: <i>POSou GUI</i>  Clic droit: <i>Menu</i> --command=bash -c LEFT_CLICK
Cordialement.

Posted: Thu 10 Oct 2013, 17:52
by seaside
I mean, if there are several yad apps running at the same time, what could distinguish the one I have to kill from the others?
One approach is to track the pid when the process is created with a unique identifier.

Code: Select all

yad &
yad_program-pid=$! # OR
 
# If you need to keep the pid in a tmp file
 echo $! >/tmp/yad_program-pid
Then you can kill that specific pid --"kill $yad_program-pid"

Cheers,
s

Posted: Fri 11 Oct 2013, 10:36
by Argolance
Bonjour,
One approach is to track the pid when the process is created with a unique identifier.
Thank you seaside.
This is obviously the more known/simple way to get the pid of a process (and I already explored it!) but, in my case, this doesn't give me the pid of the yad process itself, but the pid of the the script from which yad is run.
So, lines I found above are not very pretty but work quite perfectly... and I understand how they work! :wink:
I actually don't see how to adapt/make Karl Godt code lines work in my script. As far as I know, they actually don't.

Cordialement.

Posted: Fri 11 Oct 2013, 11:05
by Karl Godt
Hi Argolance !

I myself misunderstood your code, especially misinterpreted *POSou: pattern.
I thought that would be "$POSou" - a variable , since functions make much sense
when they could be used several times by

KillYad ARGUMENT1 [ ARGUMENT2 ]

.

What you want to do is to kill a specific yad-GUI for "ToOpPy EST À JOUR! "

As stated you can get the process-id by assigning VARIABLE1=$!

Then call

KillYad VARIABLE1

.

My code with grep -w "$1" would treat $1 as $VARIABLE1 in the grep pipe , while the awk $1 should be awk specific .

*

For the sub-script problem it seems that it needs to be fixed inside the sub-script , by for example assigning

SUB_SCRIPT_PID=$$
echo $YAD_PID >/tmp/${SUB_SCRIPT_PID}.pid

inside the sub-script
and with the sub-script-pid by $! at the main script it should be accessible by

read YAD_PID </tmp/${!}.pid
kill -15 $YAD_PID

Posted: Fri 11 Oct 2013, 13:08
by mikeb
If i follow the need correctly you need a unique identifier for one particular yad process but outside of a script.

One approach I had was to make a unique sysmlink to say yad in /tmp...eg /tmp/yad-myscript

then launch your yad from /tmp/yad-myscript ... this then appears in such as pidof or ps as a unique running process thats easy to kill independantly.

Think in terms of mplayer and gmplayer...

mike

Posted: Fri 11 Oct 2013, 16:05
by Argolance
Thank you mikeb!

Posted: Fri 11 Oct 2013, 16:19
by Argolance
I finally kept my solution and "pruned it away": this is very simple and seems to work fine: 8)

Code: Select all

KillYad(){
		YAD_PID=`ps | grep yad | grep -w POSou | cut -d" " -f 1`
		kill -15 $YAD_PID
But, is there any contraindication to use it or something to add to make it better?

Cordialement.

Posted: Fri 11 Oct 2013, 17:34
by mikeb
No thats how I would normally do it if using $! was not possible

the create a tmp link is handy if say you had several yads running from multiple scripts that may no longer exist eg usin exec or &

mike

Posted: Tue 22 Oct 2013, 13:42
by Argolance
Bonjour,
To dowload the latest 0.23.1 yad version: :arrow: http://www.murga-linux.com/puppy/viewto ... 6&start=60

Cordialement.