How to place an executable icon in the systray area?[SOLVED]

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
User avatar
Mike Walsh
Posts: 6351
Joined: Sat 28 Jun 2014, 12:42
Location: King's Lynn, UK.

How to place an executable icon in the systray area?[SOLVED]

#1 Post by Mike Walsh »

Afternoon, boys & girls.

This may be the right place for this, it may not.....but here goes anyway.

What would be the easiest way to get an icon to show up in the system-tray area (for a small utility I'm developing)? All I need is for this icon to execute a simple script when 'clicked' upon each time.

I suspect this may turn out to be somewhat more involved than I think it will..! :)

Am I right in thinking GTK is involved here? Scripting is not my strong point, but I'm steadily picking up more & more as time goes by; this is the first time I've wanted to include something like this into a package, and I'm a wee bit lost as to where to go next.

Any ideas/suggestions/tips would, as usual, be very much appreciated.

TIA.


Mike. :wink:
Last edited by Mike Walsh on Tue 13 Mar 2018, 00:15, edited 2 times in total.

User avatar
drunkjedi
Posts: 882
Joined: Mon 25 May 2015, 02:50

#2 Post by drunkjedi »

Hey Mike,
If I remember correctly (I am at work and can't check ATM),
Look inside file ~/.jwmrc-tray
You will get pretty good idea what needs to be done.
Just append some line in given format.
Give a name, then icon location, then what script or command to execute.

If you want to do it with a pet, you may need to make a post install script which will append those lines to the file.

In an sfs it is also possible, just place a script which will append those lines in /root/startup folder. (I have played with this before, and I am purely using my memory to answer, slight corrections maybe needed).

I found fatdog's sfs loading system more aofasticated as it givea me option to run scripts on manual sfs load/unload, also on system load/unload (shutdown/reboot).

But that's another topic.

Hope this helps.

User avatar
Mike Walsh
Posts: 6351
Joined: Sat 28 Jun 2014, 12:42
Location: King's Lynn, UK.

#3 Post by Mike Walsh »

Hi, DJ.

Mm. I know where you're coming from; that'll put a 'clickable' icon in the left-side 'launcher' area.....which is not quite what I want.

According to /root/.jwmrc-tray, I need my icon to be over on the right-hand side, among all that <Swallow> and 'Blinky' stuff (which I can't make head or tail of, I'm afraid).....

What I'm after is the method by which a GTK app will place an icon in the 'system' tray area, on the right-hand side of the tray. Scripting is not my strong point, though I'm slowly getting there..!


Mike. :wink:

User avatar
drunkjedi
Posts: 882
Joined: Mon 25 May 2015, 02:50

#4 Post by drunkjedi »

Make the code as in left side area and put it in the swallow area before the code for clock.
And you will get the icon there. That's what I remember.

I will be going home in half hour, but it will be midnight, so will check tomorrow morning and report back to you.

jafadmin
Posts: 1249
Joined: Thu 19 Mar 2009, 15:10

#5 Post by jafadmin »

Here's a demo in 'C' (freememaplet)that Barry did back in the day. It covers the basic concepts. It is what I started with. The other one is the absolute bare bones "hello world" kind of a demo ..
Attachments
skeleton.c.tar.gz
(600 Bytes) Downloaded 141 times
freememapplet_tray-2.4.tar.gz
(7.09 KiB) Downloaded 149 times

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#6 Post by musher0 »

Hello, Mike_Walsh.

IMO, all you need is the Yad utility, which all recent Puppies offer:

Code: Select all

yad --notification --command='/path/of/your/script' --image=/path/of/your/png_icon 2>/dev/null
You can create a wrapper script for the one-liner above and save it in
/root/Startup. Then, at every boot, your script will be available from the system
tray area by clicking on the icon you chose for it.

I am not sure if Yad versions before 0.12.4 have that "--notification" capacity.

~~~~~~~~~~~~~~

For the record, "many" years ago, technosaurus (et al.) worked on a tray icon
utility with right-click and left-click, so you could call two apps with it. It is hiding
well in a froum thread which I cannot find at the moment -- but which I was able
to find two weeks ago! It was called "sit", like the dog command.

Heads up:
Even the latest version of "sit" is in an incomplete state, IMO. I say that because I
("me", "moi", "ego") was not able to make "heads or tails" of it, speaking of
which... Then I discovered the "--notification" feature in yad.

I am writing the novelette above in the hope that one of our C devs will pick up
the hint and finish the promising job that technosaurus has started -- with a good
how-to would not hurt a bit either!

IHTH.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#7 Post by fredx181 »

Hi Mike, indeed as musher0 said, yad works well for it, here's simple script, just change path for TRAY_ICON, POPUP_TEXT and /path/to/program (in the function on_click)
(can be extended also with right-click menu, but then becomes a little more complicated)

Code: Select all

#!/bin/bash

# Set the path to tray icon and set popup text
TRAY_ICON="/usr/share/pixmaps/disc.png"
POPUP_TEXT="Click Me"

function on_click() {
# Execute program
/path/to/program
## ... do some more if desired
}
export -f on_click

function on_exit() {
echo "quit" >&3
rm -f $PIPE
}
export -f on_exit

trap on_exit EXIT

export PIPE=$(mktemp -u /tmp/${0##*/}.XXXXXXXX)  # EDITED
mkfifo $PIPE
exec 3<> $PIPE
## Run yad and tell it to read its stdin from the file descriptor ####
yad --notification --text="$POPUP_TEXT" --listen \
--image="$TRAY_ICON" \
--text="$POPUP_TEXT" \
--command="bash -c on_click" <&3
EDIT: changed the export PIPE=... line to:

Code: Select all

export PIPE=$(mktemp -u /tmp/${0##*/}.XXXXXXXX)
see also here: http://murga-linux.com/puppy/viewtopic. ... 272#985272

Fred
Last edited by fredx181 on Mon 12 Mar 2018, 12:52, edited 2 times in total.

User avatar
Mike Walsh
Posts: 6351
Joined: Sat 28 Jun 2014, 12:42
Location: King's Lynn, UK.

#8 Post by Mike Walsh »

@jafadmin, musher0, fredx181:-

Wow. Thanks for the responses, guys; that little lot will give me something to chew on for a wee while..!

I have to confess, I've rather gotten used to small apps/utilities that 'run from the tray'. Yes, you can make a MenuEntry for them, then put it in the JWM 'launcher area', on the left hand side.....but it's more technically 'satisfying' to have 'em appear in the correct place, in the system tray.

This small utility I'm working on will only need a single-click upon it to execute it. It works 100% already.....but I'd like to get this 'systray' bit nailed-down, since I may wish to utilise this same trick in future.

---------------------------------

@ jafadmin:-

Thanks for the demo. I'll have a gander at it later on this afternoon, when family are out of the way (it's Mother's Day here in the UK!)

@musher:-

Yes, I too had forgotten about 'yad'. I've not really experimented much with it, but I've seen no end of mentions about it in recent years. It does sound like what I want; easy-to-use and simple. I'll have to have a play around with it.

Come to that, of course, there's 'zenity', too, isn't there? I'll have to hunt down the usage instructions for that.....see if it'll support executable tray icons, etc.

@fredx181:-

That looks.....complicated, Fred..! (Although I'll own, I wouldn't mind being able to incorporate a right-click menu as well at some point.) I'll try this out, and see what it does... Good example, though. Cheers.

One query, while I think about it. How does any of this stuff differentiate between a left-clk and a rt-clk, anyway? What triggers it?

----------------------------

Thanks, everybody!


Mike. :wink:

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#9 Post by fredx181 »

Hi Mike, for menu you can add this for example before the 'yad --notification ...' command:

Code: Select all

echo "menu:Edit!geany!gtk-edit|File manager!rox!gtk-home|Quit!quit!gtk-quit" >&3
It's in the form of: echo "menu:<Name>!<command>!<icon>|<Name>!<command>!<icon>|.... etc...
So then becomes:

Code: Select all

#!/bin/bash

# Set the path to tray icon and set popup text
TRAY_ICON="/usr/share/pixmaps/disc.png"
POPUP_TEXT="Click Me"

function on_click() {
# Execute program
/path/to/program
## ... do some more if desired
}
export -f on_click

function on_exit() {
echo "quit" >&3
rm -f $PIPE
}
export -f on_exit

trap 'on_exit' EXIT

export PIPE=$(mktemp -u /tmp/${0##*/}.XXXXXXXX) # EDITED, see below
mkfifo $PIPE
exec 3<> $PIPE

# Example right-click menu
echo "menu:Edit!geany!gtk-edit|File manager!rox!gtk-home|Quit!quit!gtk-quit" >&3

yad --notification --kill-parent --text="$POPUP_TEXT" --listen \
--image="$TRAY_ICON" \
--text="$POPUP_TEXT" \
--command="bash -c on_click" <&3
EDIT: changed the export PIPE=... line to:

Code: Select all

export PIPE=$(mktemp -u /tmp/${0##*/}.XXXXXXXX)
see also here: http://murga-linux.com/puppy/viewtopic. ... 272#985272

Fred
Last edited by fredx181 on Mon 12 Mar 2018, 12:52, edited 2 times in total.

User avatar
Mike Walsh
Posts: 6351
Joined: Sat 28 Jun 2014, 12:42
Location: King's Lynn, UK.

#10 Post by Mike Walsh »

@fredx181:-

Now then, mate; hold your horses a mo!

As your script stands, it puts an icon in the tray, with the 'popup'. It won't put my chosen icon in the tray, despite using the full path (insists on using a little green flask; YAD trademark, or something?) in the tray....but the first part works. Sort of.... :?

As for 'click-to-execute' the program, clicking on the icon after starting the script doesn't actually do anything. It doesn't appear to execute my own script at all. (The script itself works fine; clicking on the script in /usr/bin executes it perfectly, but your script, which I've placed in /root/Startup, seems to 'stall' after putting its own icon in the tray...)

(*shrug*)

Any suggestions? You obviously know a darn sight more about this scripting business than I do..!

BTW, middle-click 'exits'. That sound about right?

Currently, it reads as follows:-

Code: Select all

#!/bin/bash 

# Set the path to tray icon and set popup text 
TRAY_ICON="/usr/share/pixmaps/green-tick.png" 
POPUP_TEXT="Spot2Root - download transfer" 

function on_click() { 
# Execute program 
/usr/bin/spot-to-root
## ... do some more if desired 
} 
export -f on_click 

function on_exit() { 
echo "quit" >&3 
rm -f $PIPE 
} 
export -f on_exit 

trap on_exit EXIT 

export PIPE=$(mktemp -u --tmpdir ${0##*/}.XXXXXXXX) 
mkfifo $PIPE 
exec 3<> $PIPE 
## Run yad and tell it to read its stdin from the file descriptor #### 
yad --notification --text="$POPUP_TEXT" --listen \ 
--image="$TRAY_ICON" \ 
--text="$POPUP_TEXT" \ 
--command="bash -c on_click" <&3

.....but neither executes /usr/bin/spot-to-root, nor uses /usr/share/pixmaps/green-tick.png. (uses a little green 'flask' instead ???)

------------------------------------------------------

Yep, looks like it.

Image

The little green 'flask' symbol does indeed appear to be YAD's 'trademark', So why won't it use my icon.....or doesn't it like PNGs? :roll: Hmm....

----------------------------------------------------------

Out of curiosity, what does that final stanza do?

Would this be anything to do with the version of yad in use, BTW? I get this:-

Code: Select all

# yad --version
0.38.0 (GTK+ 2.24.10)
(Sorry for all the questions, mate...)


Mike. :wink:

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#11 Post by musher0 »

Hi Mike_Walsh.

I believe yad dislikes strngs. I would suggest that you edit your script to indicate
the direct targets for the executable and the icon. Also, what are those "lonely"
forward slashes doing there? ;) Does bash really understand them? I never got
them to work.

About zenity: my xenialPup-7.0.6 has yad version 0.12.4, and I read somewhere in
its docs that this version supersedes zenity. (Unless my old brain is inventing
things because Puppy Linux is not stimulating it enough. [Ha!])

This is what I have for a mini-aemenu offering access to my mounted partitions and
to a "compass" through the Puppy hierarchy.

Code: Select all

#!/bin/sh
# /root/Startup/yadBoussPart.sh
# Objectif : créer une icône dans le panier pour le script d'aemenu « Boussole-e
# à /root/.aewm/ae/Boussole-et-Partitions.sh.
# (c) musher0, 2018/02/25 20:06. GPL3. Rev.: 2018-03-11.
####
cd /root/.aewm/ae
# echo "Le script yadBoussPart.sh est utilisé. | ############ (Was useful
# Script yadBoussPart.sh is being used" > /tmp/yadBoussPart # during test.)
sleep 0.5s
yad --notification --command='/root/.aewm/ae/Boussole-et-Partitions-yad.sh' --image=/root/.aewm/ae/boussole_4a-28x.png 2>/dev/null
# Note -- # yad n'aime pas le fion ~ pour /root.
That last sentence means "yad does not like the wave sign ~ for /root." It wants the path written in full.

Illustration attached.

IHTH.
~~~~~~~~~~
PS. (everning) -- Full yad command line now provided. I had truncated it inavertently
when I pasted it here. the first time. Sorry about that.
Attachments
yad-compass.jpg
(37.64 KiB) Downloaded 280 times
Last edited by musher0 on Mon 12 Mar 2018, 01:56, edited 1 time in total.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

some1
Posts: 117
Joined: Thu 17 Jan 2013, 11:07

#12 Post by some1 »

Mike Walsh

You are right - I was wrong.

But ...
Using this:

Code: Select all

TRAY_ICON="/usr/local/share/icons/default_left_ptr.png"
Your code/Yad displays the specified icon in the task-bar.
Last edited by some1 on Mon 12 Mar 2018, 00:53, edited 1 time in total.

User avatar
Mike Walsh
Posts: 6351
Joined: Sat 28 Jun 2014, 12:42
Location: King's Lynn, UK.

#13 Post by Mike Walsh »

@musher0:-

Frankly, mate, I don't see how I can get much more direct than

Code: Select all

/usr/share/pixmaps/green-tick.png
...for the icon, and

Code: Select all

/usr/bin/spot-to-root
...for the executable. Tell me how that can be improved upon...

As for those 'lonely' backslashes.....search me, mate. It's mostly Greek to me, I'm sorry to say. Scripting is not my strong point..!

(See my reply to some1, below).

------------------------------------------

@ some1:-

TBH, I'm using the script pretty much as Fred offered it to me.....with the exception of changing the necessary paths for my own. But for the sake of propriety, I did check beyond those continuation backslashes. The spaces are there.

-------------------------------------------

And it can't be anything to do with the version of yad in use. I downloaded the latest version from SourceForge, and compiled it earlier this evening. The system's now running

Code: Select all

# yad --version
0.40.0 (GTK+ 2.24.10)
So I very much doubt that's got owt to do with it...


Mike. :wink:

some1
Posts: 117
Joined: Thu 17 Jan 2013, 11:07

#14 Post by some1 »

Hi
Mike -
Try the attached file.

Its your code -adapted a bit,so that it works for me.
Main thing:I deleted trailing spaces after the continuation backslashes.
:lol:
Attachments
MW_fake.gz
(785 Bytes) Downloaded 127 times

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#15 Post by musher0 »

Hello, Mike_Walsh.

Here is my take on it. I adapted fredx' original.

I did learn a few things along the way, e.g. how he uses the file descriptors. I had read
the theory of it, but had always wondered how to do it in practice; now I know.
Thanks, fredx.

This is the tree of the attached pet:
forMW-0.1
[ 108] forMW-0.1/pet.specs
[4.0K] forMW-0.1/root
[4.0K] forMW-0.1/root/my-applications
[4.0K] forMW-0.1/root/my-applications/bin
[5.0K] forMW-0.1/root/my-applications/bin/playsound_simple
[1.0K] forMW-0.1/root/my-applications/bin/yad-fredx-mod.sh
[4.0K] forMW-0.1/root/my-documents
[4.0K] forMW-0.1/root/my-documents/icons
[2.9K] forMW-0.1/root/my-documents/icons/application_view_list-32x-orange.png
[4.0K] forMW-0.1/usr
[4.0K] forMW-0.1/usr/share
[4.0K] forMW-0.1/usr/share/audio
[ 35K] forMW-0.1/usr/share/audio/sonnette-velo2.mp3
8 directories, 5 files
I put a bicycle chime for the on_click function.

It took me a while to find out that that function was for LEFT-CLICK ONLY. It is
independent from what exists on the "echo line" further down, which is the menu proper,
activated by RIGHT-CLICK.

So when you will do a LEFT click on the icon, it will chime. When you will do a RIGHT
click on the icon, the mini-menu will show up. I have also replaced fredx' original calls on
the "echo line" with two Puppy default executables, with parameter. That works fine; no
need, for either the initial double commands or the full path.

As you can see from the above tree, also included is a tiny mp3 player (I think forum
member technosaurus wrote it) , and an orangy list icon.

~~~~~~~~~~~~~~~~

This is fredx' script modified by me. Constructive feedback appreciated: this is how
we learn.

Code: Select all

#!/bin/bash
# par fredx # modifié par musher0
# Source: http://murga-linux.com/puppy/viewtopic.php?p=985208&sort=lastpost#985208
# Relevé le 2018/03/11 22:00
####
# Set the path to tray icon and set popup text
TRAY_ICON="/root/my-documents/icons/application_view_list-32x-orange.png"
# "/usr/share/pixmaps/disc.png"
POPUP_TEXT="Click Me"
SounD="/usr/share/audio/sonnette-velo2.mp3"
function on_click() {
# Execute program # on LEFT CLICK!!!
# /path/to/program
/root/my-applications/bin/playsound_simple /usr/share/audio/sonnette-velo2.mp3
## ... do some more if desired
}
export -f on_click

function on_exit() {
echo "quit" >&3
rm -f $PIPE
}
export -f on_exit

trap 'on_exit' EXIT

export PIPE=$(mktemp -u --tmpdir ${0##*/}.XXXXXXXX)
mkfifo $PIPE
exec 3<> $PIPE

# Example right-click menu
echo "menu:Edit!defaulttextviewer new.txt|File manager!defaultfilemanager /root|Quit!quit" >&3

yad --notification --kill-parent --text="$POPUP_TEXT" --listen \
--image="$TRAY_ICON" \
--text="$POPUP_TEXT" \
--command="bash -c on_click" <&3 2>/dev/null
~~~~~~~~~~~~~~~~~

The pet archive is attached. I don't know if any of this will help you, but there goes!

BFN.
Attachments
forMW-0.1.pet
(40.35 KiB) Downloaded 150 times
Last edited by musher0 on Mon 12 Mar 2018, 07:49, edited 1 time in total.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#16 Post by greengeek »

Mike Walsh wrote:Hi, DJ.

Mm. I know where you're coming from; that'll put a 'clickable' icon in the left-side 'launcher' area.....which is not quite what I want.

According to /root/.jwmrc-tray, I need my icon to be over on the right-hand side, among all that <Swallow> and 'Blinky' stuff (which I can't make head or tail of, I'm afraid).....

What I'm after is the method by which a GTK app will place an icon in the 'system' tray area, on the right-hand side of the tray. Scripting is not my strong point, though I'm slowly getting there..!


Mike. :wink:
Hi Mike, I would like to understand your terminology. Are you able to post an image showing what you consider the left and right areas to be? "System tray" is a windows construct.

I view it this way:
The left side of the tray is for launching.
The right side of the tray is for displaying info.

Do i have this wrong?

What are you wanting to do on the right hand side?

cheers!

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#17 Post by musher0 »

Hi, greengeek.

Technically, on Linux, I believe it is called the "notification area". Not that the area in itself
is really "notifying" the user of anything, it's just there.

Maybe an expression like "active icons area" would be more telling. It is obviously an area;
there are icons there; they all do an action when the user clicks on them. For some, that
action is a notification to the user. (We linguists do know how to split hairs, don't we?)

Just a thought.

BFN.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#18 Post by fredx181 »

Hi Mike and all,

Mike, can you run the "tray icon" script in terminal and see if there are errors ?

Assuming your path for the icon at TRAY_ICON= and the path for command in "on_click" function are correct, I can't understand why it wouldn't work for you. :roll:

One important thing for this line:

Code: Select all

export PIPE=$(mktemp -u --tmpdir ${0##*/}.XXXXXXXX)
It may work on most systems, but better change to:

Code: Select all

export PIPE=$(mktemp -u /tmp/${0##*/}.XXXXXXXX)
Some puppies (or most ?) use busybox mktemp , it doesn't have the "--tmpdir" option and it will fail.
(just found out by testing on D-pup-Stretch, which does indeed use busybox mktemp)
EDIT: Edited my above posts by changing this in the code, also just received a PM from someone (thanks!) with confirmation that the problem was because of that earlier line.

About the backslashes at the "yad --notification" command, these are just common use for to give better overview (specially for long commands) but may give problems when doing copy and paste, so can be this (oneliner) as well:

Code: Select all

yad --notification --kill-parent --text="$POPUP_TEXT" --listen --image="$TRAY_ICON" --text="$POPUP_TEXT" --command="bash -c on_click" <&3
Worth trying to change to the above and see if it works then.

Fred

stemsee

#19 Post by stemsee »

musher0 wrote:Hi, greengeek.

Technically, on Linux, I believe it is called the "notification area". Not that the area in itself
is really "notifying" the user of anything, it's just there.

Maybe an expression like "active icons area" would be more telling. It is obviously an area;
there are icons there; they all do an action when the user clicks on them. For some, that
action is a notification to the user. (We linguists do know how to split hairs, don't we?)

Just a thought.

BFN.
How then does 'active icons area' differ to the desktop?

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#20 Post by musher0 »

stemsee wrote:
musher0 wrote:Hi, greengeek.

Technically, on Linux, I believe it is called the "notification area". Not that the area in itself
is really "notifying" the user of anything, it's just there.

Maybe an expression like "active icons area" would be more telling. It is obviously an area;
there are icons there; they all do an action when the user clicks on them. For some, that
action is a notification to the user. (We linguists do know how to split hairs, don't we?)

Just a thought.

BFN.
How then does 'active icons area' differ to the desktop?
I wish I knew!!!! :lol:
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

Post Reply