About yad [SOLVED]

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

About yad [SOLVED]

#1 Post 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.
Last edited by Argolance on Wed 09 Oct 2013, 20:33, edited 2 times in total.

User avatar
matiasbatero
Posts: 60
Joined: Fri 12 Oct 2012, 01:27
Location: Mar del Plata, Argentina

Yad notification

#2 Post 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="

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#3 Post 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.
Attachments
130914_231432_3200x1200_easyshot.png
(15.66 KiB) Downloaded 1195 times
130914_224546_3200x1200_easyshot.png
(20.98 KiB) Downloaded 1206 times
Last edited by Argolance on Sun 15 Sep 2013, 08:08, edited 1 time in total.

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#4 Post 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 "!$" !

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#5 Post by Argolance »

Thank you Karl! :D

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#6 Post 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.

User avatar
matiasbatero
Posts: 60
Joined: Fri 12 Oct 2012, 01:27
Location: Mar del Plata, Argentina

#7 Post 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..

User avatar
matiasbatero
Posts: 60
Joined: Fri 12 Oct 2012, 01:27
Location: Mar del Plata, Argentina

#8 Post 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]

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#9 Post by Karl Godt »

--kill-parent
killed PID Nr 1 - literally init , that led to immediate reboot .

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#10 Post 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.

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#11 Post 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."
}

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#12 Post 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.

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#13 Post 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

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#14 Post 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.

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#15 Post 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

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#16 Post 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

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#17 Post by Argolance »

Thank you mikeb!
Last edited by Argolance on Fri 11 Oct 2013, 16:59, edited 1 time in total.

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#18 Post 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.

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#19 Post 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

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#20 Post by Argolance »

Bonjour,
To dowload the latest 0.23.1 yad version: :arrow: http://www.murga-linux.com/puppy/viewto ... 6&start=60

Cordialement.

Post Reply