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
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#21 Post by MochiMoppel »

stemsee wrote:How then does 'active icons area' differ to the desktop?
Let's forget 'active icons area'. The notification area, which JWM refers to as "Dock", may contain icons and these icons may be clickable, but this is not a requirement. I run a script in the notification area that keeps track of the battery status. Looks like the clock, no icon and definitely not clickable,

Simply speaking: Desktop and notification area are owned by the window manager. The WM runs programs either windowed on the desktop or windowless in the notification area.

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

#22 Post by fredx181 »

There was request through PM to clarify (thought I post my answer here also)
Re the line:
Code:
## ... do some more if desired


would you be so kind as to expand upon its meaning and how it works
You can put several commands after each other in the function on_click, e.g.

Code: Select all

function on_click() {
# Execute program
command1
# ... do some more if desired
command2
# again one more
command3
}
export -f on_click	

In this case command2 will run when command1 has exited, but for example to run command2 while command1 is still busy, run it in the background with a "&" :

Code: Select all

command1 &



Hope this clarified.

Fred

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

#23 Post by musher0 »

Fine. Thank you, fredx.

Could you use that left-click sub-routine to run another menu similar to what you have
at the "echo line"?

Or even have something for middle-click?

To prevent tendinitis in the wrist, I use a Logitech "Marble" track-ball
Image
instead of a regular mouse, and it has left-click, right-click, middle-right-click and
middle-left-click. Some other computer mice have as many buttons or more.

Is it possible to configure a single yad icon to use all four buttons?
Is the yad utility limited in this respect?

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

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

#24 Post by Mike Walsh »

Right then, boys & girls. I see y'all have been busy in my absence.... :D

Let's see if I can answer these posts in some kind of order.

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

@fredx181:-

Running the script as is, from the terminal, produces absolutely no output at all. However, the terminal won't return to the prompt; it just sits there, with the cursor blinking at me, mid-stride (as it were)...

I've moved things around a bit; icon now lives in /usr/local/share/icons (as suggested by some1), and the executable (my 'spot-to-root' script, now lives in /usr/local/bin.

Your script has been modified to reflect this.....including your suggested change from

Code: Select all

export PIPE=$(mktemp -u --tmp/${0##*/}.XXXXXXXX)
...to:-

Code: Select all

export PIPE=$(mktemp -u /tmp/${0##*/}.XXXXXXXX)
I've also added 'exec' to the executable's line (just to make sure this wasn't the problem)....thus:-

Code: Select all

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

Now, then: running the modified script from urxvt now gives this output:-

Code: Select all

# /root/Startup/S2R.sh
Usage: mktemp [-V] | [-dqtu] [-p prefix] [template]
BusyBox v1.21.0 (2013-02-18 15:57:06 WST) multi-call binary.

Usage: mkfifo [-m MODE] NAME

Create named pipe

	-m MODE	Mode (default a=rw)

/root/Startup/S2R.sh: line 24: $PIPE: ambiguous redirect
.....which refers to this line:-

Code: Select all

exec 3<> $PIPE 
Any suggestions? Just FYI, I'm doing all this in Slacko 570.

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

@musher0:-

I'll have a look at yr .pet in a wee while, and let ya know what (if anything) happens. Cheers.

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

@greengeek:-

Yah; I agree with your assessment. 'Systray' is a hangover from my Windoze days, it's true.

I want to place an icon in the notification area which, when clicked upon, will execute a small script. That's all I want it to do.

The script merely moves stuff from one directory to another, via an 'intermediate', temporary folder, changing ownership permissions as it does so. It then displays a small Zenity window to let me know the script has run successfully. I'm experimenting with Bash, and YAD/Zenity, and trying out something I thought of which was inspired by the way that current Chrome insists on running as 'spot'.

That all works fine if you click directly on my own script. It's getting it to run from an icon in the notification area that's proving to be, um.....problematic.

It seems it doesn't matter where I place my icon that I want to use for this, fred's script simply doesn't seem to want to pick it up. Yad insists on displaying its default 'green flask' icon instead. Mind you, I'm not blaming Fred; it's like as not my system is playing 'silly buggers' for some reason....

I was trying to base this on a small utility Bill (rcrsn51) wrote a few years ago to 'switch' Adobe's FlashPlayer 'on' or 'off', as required. He let me have his build-script and code for it, which I successfully modified to work with PepperFlash instead.

You click on the tray icon for it; it turns FlashPlayer off by simply appending the '.off' extension, so FlashPlayer isn't recognised, and changes the icon colour. You click on it again, ; it removes the '.off' extension, so FlashPlayer will work again, and resets the icon colour back to original.

Trouble is, I don't know enough about Bash & scripting in general yet (I stress yet) to be able to recognise which bits of the script are doing what! Oh, I recognise some of it.....but I can't 'read' the whole thing from start to finish of any given script. I don't understand the 'language' well enough at this point in time.....and I don't have as much time to spare as I would like, to be able to spend hours playing around & experimenting.

Stuff like 'pipe'; 'grep'; 'awk'; 'sed'....things like that; it's complete Greek to me. I'd like nothing better than to spend several hours at a time experimenting and teaching myself from the ground up.....but life gets in the way, doesn't it? So I try to pick up bits & pieces here and there as and when I can. Don't get me wrong; I can script stuff now that I could never have imagined doing when I started with Pup nearly 4 years ago. It's all good fun. We all have different learning curves with this kinda thing. Some folks pick it up as naturally as breathing. For others, it's a tooth-and-claw uphill struggle, every step of the way..!! :roll: :lol: :lol:

(Kinda describes me, I think...)


Mike. :wink:

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

#25 Post by Mike Walsh »

Guys, I'm giving this up as a bad job.

I've tried this in half-a-dozen different Pups. In every single case, I get a 'green flask' in the notification area instead of my chosen icon.....and a total lack of anything happening when I click on that icon.

(@ musher:- Same lack of success using your modified script, mate.)

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

The script had a MenuEntry written for it a few days ago.

If I click direct on the script in /usr/local/bin.....it runs.

If I click on the MenuEntry....it runs.

If I put a shortcut for the MenuEntry in the launcher area, and click on that.....it runs.

But from the icon in the notification area.....nada. Zilch. Nowt 'appens. It appears to be working fine for everybody else.....but it just will not work for me..!

Can't work that one out. At all.

My best solution is to run it from the icon in the 'launcher area'. Not exactly what I wanted, but it'll have to do. For some reason, all variations of this script simply will not 'see' the executable and the icon on my systems.

Thanks for everybody's efforts; I'm really sorry to have wasted your time.


Mike. :oops:

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

#26 Post by musher0 »

Hi Mike_Walsh.

You did something bad to that script while writing it, and now it's getting back at you! :lol:
It somehow knows you want it to run from the tray, but it's sticking its tongue at you: it will
work from anywhere else, but not from there, tra-lala! (This is a joke!) :)

Welcome to the club!!! ;) (I too have a few scripts like that, who think they are funny!!!)

Seriously: have you made your script executable? As in

Code: Select all

chmod +x script.sh
Sometimes we complicated bipeds forget about the simplest things...

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

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

#27 Post by musher0 »

Hello again folks.

I just found out that former member stu91 juggled with this before we did:
http://www.murga-linux.com/puppy/viewto ... 1604b53c46

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

#28 Post by fredx181 »

@ Mike Walsh
Nooooo... !! Don't give up, you may be close to a solution !
I understand the frustration, though, sometimes things are so f*ckin' mysterious :wink:
Seeing your output:

Code: Select all

# /root/Startup/S2R.sh
Usage: mktemp [-V] | [-dqtu] [-p prefix] [template]
It looks like still something's going wrong with the mktemp command on your system.
(otherwise it wouldn't show it's usage info)
So instead of:

Code: Select all

export PIPE=$(mktemp -u /tmp/${0##*/}.XXXXXXXX)
Try to make it simply (no mktemp command involved), just:

Code: Select all

export PIPE="/tmp/S2R.$RANDOM"
EDIT: obviously, if the PIPE variable is not set properly, the mkfifo command (after that) will fail also.
(as it doesn't know the name of the named pipe to be created then)

@musher0
Could you use that left-click sub-routine to run another menu similar to what you have
at the "echo line"?

Or even have something for middle-click?

To prevent tendinitis in the wrist, I use a Logitech "Marble" track-ball

instead of a regular mouse, and it has left-click, right-click, middle-right-click and
middle-left-click. Some other computer mice have as many buttons or more.

Is it possible to configure a single yad icon to use all four buttons?
Is the yad utility limited in this respect?
I don't think that sort of behavior can be changed from yad options.
(but I might be wrong, I'm no expert)

Fred
Last edited by fredx181 on Mon 12 Mar 2018, 19:22, edited 3 times in total.

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

#29 Post by musher0 »

Thanks, fredx.

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

@all.

Related to the subject at hand, I wrote a bit of a rant, plus
hopefully a useful "sdesk" script here.

After studying and testing sdesk for the equivalent of a full
day, I finally managed to make it work... I had to recompile
it for 32-bit as well. Grrr.

Maybe give this "sdesk" a try, Mike_Walsh?

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

User avatar
puppy_apprentice
Posts: 299
Joined: Tue 07 Feb 2012, 20:32

#30 Post by puppy_apprentice »

You can add your script to Parcellite actions menu. There is only one drawback - Parcellite icon will disappear, but if you click on area when you last saw it Parcellite will work as normal. When you reload graphical server it will appear again.

saveclips:

Code: Select all

#!/bin/sh
strings /root/.local/share/parcellite/history
exit 0
There is option in new Parcellite for saving clips to txt file, but i use still original one from Salcko 5.7 ;)
Attachments
parcellite_actions_2.jpg
Edit actions window
(26.46 KiB) Downloaded 90 times
parcellite_actions_1.jpg
Control + LMBC
(9.99 KiB) Downloaded 93 times

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

#31 Post by fredx181 »

Hi again Mike,
Just thinking, if your only need is simply to click on the icon and execute your script, just try musher0's suggestion for a one-liner (at one of the first posts in this thread)
Something like (this avoids the PIPE creating stuff, which has more possibilities (such as right-click menu), but apparently could be problematic, as you experienced):

Code: Select all

yad --notification --command='/usr/local/bin/spot-to-root' --image='/usr/local/share/icons/green-tick.png' 2>/dev/null
Should work ! (I'll eat my hat if it doesn't :) )

Fred

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

#32 Post by Mike Walsh »

Hi, Fred.

Hm. I must have missed that one, somehow...

Just tried it out, and.....no need to go any further, mate. That does exactly what I want. How does that mantra go? 'K.I.S.S..' (Keep it simple, stupid... :lol: )

I've learnt quite a bit during the course of this thread.....about Zenity/Yad, for one thing. (And how it seems to be very easy to get carried away when you're scripting... :lol:)

Credits to both you and musher0. The final 'S2R.sh' script looks like this:-

Code: Select all

#!/bin/sh
#
#YAD 'one-liner' from musher0 / fredx181, to place executable tray icon in notification area
#
yad --notification --text="S2R file transfer" --command='/usr/local/bin/spot-to-root' --image='/usr/local/share/icons/green-tick.png' 2>/dev/null
I've added in the code for the tooltip text. Which gives us this:-


Image

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

The script to run is this one:-

Code: Select all

#!/bin/sh
#
# spot chown script to return ownership to root & move files between directories - Mike Walsh (02/02/17)
#
# Move contents of ~/Spot/Downloads to intermediate folder, change ownership, then move those files to your 'Downloads' folder 
#
mv -v ~/spot/Downloads/* /usr/share/Spot2Root/
chown root:root -R /usr/share/Spot2Root/
mv -v /usr/share/Spot2Root/* ~/Downloads/"#1CHROME_Downloads"
#
# Finish by deleting contents of Spot2Root ready for next time
#
rm -rf /usr/share/Spot2Root/*
#
# Run Zenity dialogue to confirm transfer was successful
#
zenity --info --title="File transfer successful..." --text="Your files have been transferred to
/root/Downloads/#1CHROME_Downloads
------------------------------------------------------
        Ownership has been changed
                     to root:root"
(I had to enclose the target directory in "quotes" because I use the hash mark (#) in the folder name. Bash (of course) interprets it as a 'comment out' symbol, doesn't it? :roll:)

I also added a Zenity info-text box which confirms the transfer was successful:-

Image

And before anyone says it, yah, I know Zenity is the forerunner of YAD.....but I happen to think it just looks neater, somehow.


And what all this ultimately does, is as follows; a wee video to demonstrate:-

https://www.youtube.com/watch?v=eWZPd5H ... e=youtu.be

(Apologies if the first few seconds of this are 'out-of-focus'. For some unknown reason, my YouTube vids always seem to do this....)

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

Postscript/background:- What prompted all this was the way in which current 64-bit Chrome will only run as 'spot' (Pup's equivalent of a 'normal user'). This, for me, is in Tahr64. However, I'm also running an older version of the Iron browser as 'spot' in Slacko 570. Both download with 'spot' permissions; this was an interesting wee excercise in seeing whether I could script a method for moving these from ~/spot/Downloads to a dedicated folder in my main 'Downloads folder (which is sym-linked into every Pup from a remote partition).....and change ownership along the way.

It's also taught me about some of the basic Bash commands.....which I've been meaning to get a handle on for ages. I started working on this script sometime around 12 months ago, when peebee and I both had to start employing methods to fool Chrome/Chromium into thinking it was running as a normal user.....even while running as /root. This is when head honcho Micko pointed me towards Iguleder's libpuppygc.so; a small library Iggy had written to do exactly this, implemented via the 'LD_PRELOAD' command:-

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

.....so, for a while (at least), this got put aside again.

Anyway, it's been an interesting excercise in joining-up several bits & pieces I've been fooling around with for some time now. It's astonishing (to me, at any rate) just how many different files you need to put together even for something as basic like this...

Once again, many thanks to all who've contributed to the thread.

I'll mark this as 'Solved'! Cheers, guys.


Mike. :wink: Image
Last edited by Mike Walsh on Tue 13 Mar 2018, 10:04, edited 1 time in total.

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#33 Post by MochiMoppel »

Mike Walsh wrote:Just tried it out, and.....no need to go any further, mate. That does exactly what I want. How does that mantra go? 'K.I.S.S..' (Keep it simple, stupid... :lol: )
Hi Mike, I see that you are happy and I don't want to spoil the party, but what I still don't understand: This seems to be exactly what a much more simple TrayButton would do. Why was this never an option for you? Now you have an instance of yad running permanently, doing nothing but waiting for you to click the icon. Seems to me like a complicated way to mimic a static shortcut and a lot of waisted processing power. Or is there more to this? If you want to "start" your icon only occasionally I would see a point, but without such background info I'm puzzled.

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

#34 Post by Mike Walsh »

Morning, Mochi.

'TrayButtons'... Hm. I think that's what drunkjedi was talking about back near the start of this thread, wasn't it?

I tried this, Mochi, but simply could not get a TrayButton to show up on the right-hand side (in the notification area). I'll own that I'm still pretty much a noob with all this kinda stuff, so.....it's quite 'on the cards' that I wasn't doing it correctly, or didn't have my syntax right, or something like that.

If there's a simpler way of doing this kind of thing.....I'm all ears. The K.I.S.S principle works pretty well for most things; the less there is to go wrong, the better, as far as I'm concerned.

YAD got mentioned during this thread; YAD and Zenity are both things I've been meaning to have a play around with for a long time. Example scripts got published; more examples (with modifications) came in; okay, I admit it.....we all got kinda focused on one way of solving the problem.

I'm in the early stages of 'playing-around', and experimenting with a lot of different things, Mochi. I'm more than happy to try anything out; I've got no fixed 'conceptions' of what should (or shouldn't) be done, so.....if you have any suggestions for a different (or simpler) way of doing the above (a single, static icon in the notification area, with tooltip, which when clicked on will execute a script), then I would love to hear it.

Processing power is not really an issue here. Although this is a 12-year old desktop PC, it was powerful for its time, and has long since been 'tricked out to the max' with the highest grades and amounts of everything it'll run. Having said that, I also run an even older Puppy laptop that does have serious constraints on what it'll do.....so I'm more than happy to try out multiple ways of approaching the same problem.

:?: What would you suggest? :?:


Mike. :wink:

User avatar
puppy_apprentice
Posts: 299
Joined: Tue 07 Feb 2012, 20:32

#35 Post by puppy_apprentice »

"if you have any suggestions for a different (or simpler) way of doing the above (a single, static icon in the notification area, with tooltip, which when clicked on will execute a script), then I would love to hear it."

I'm not Mochi but i put on a table my 3 cents ;)
Attachments
try_2.png
Code
(23.9 KiB) Downloaded 225 times
try_1.png
Two buttons on right side
(8.2 KiB) Downloaded 227 times

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#36 Post by MochiMoppel »

You may not be Mochi but you can read his mind :lol:
Left of the clock is a good place for a TrayButton.

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

#37 Post by Mike Walsh »

puppy_apprentice wrote:"if you have any suggestions for a different (or simpler) way of doing the above (a single, static icon in the notification area, with tooltip, which when clicked on will execute a script), then I would love to hear it."

I'm not Mochi but i put on a table my 3 cents ;)
Well, you're both absolutely right, it seems! I've just been playing around with this for the last half-hour or so.

I wasn't aware that you could place TrayButtons anywhere on the tray. I thought these had to stay on the 'launcher' side..... (*shrug*)

I apparently didn't read drunkjedi's post carefully enough:-
drunkjedi wrote: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 thought this had to be written in 'Swallow' format, y'see; probably why I couldn't make it work.

Anyway; modifying the tail-end of /root/.jwmrc-tray to read as follows:-

Code: Select all

<!--	<Swallow name="freememapplet" width="34">
			freememappletshell
		</Swallow> -->
		<Swallow name="xload" width="32">
			xload -nolabel -bg "gray45" 
		</Swallow>
		<TrayButton popup="S2R file transfer" icon="/usr/local/share/icons/green-star.png">exec:/usr/local/bin/spot-to-root</TrayButton>
		<Clock format="%a %d %b %H:%M">PupClockset</Clock>
	</Tray>
</JWM>
....gives us this (I'm now using a green star instead of a check-mark):-


Image


.....and clicking on it, /usr/local/bin/spot-to-root executes as normal. I'm happy with that, too!

As for a 'point to all this', essentially it's there for transferring any downloads from the ~/spot/Downloads folder across to my main, sym-linked Downloads folder (which runs from a remote partition), and changing ownership along the way. Whenever I download from any browser I have running as 'spot', I can click on it and transfer the files across. Some days I may not download anything at all; other days, I may be downloading a lot of stuff, much of which I may be wanting to use straight away.

peebee has set his current Chromium builds up to automatically transfer to /root/Downloads and change ownership as it does so. I, however, have my Chrome & Chromium-based browsers set to ask me where I want to send the download to.....so if I transfer things to the specified sub-folder, I can then move them to where I want, as and when I want.

I might even set things up, now I know you can do this, to have two or three buttons (each with a different-coloured star), to send stuff to one of 3 specific folders I generally send stuff to.....

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

Quick question: I know /etc/xdg/templates/_root_jwmrc generates /root/.jwmrc. Does anything 'generate' /root/.jwmrc-tray.....or will this stay as I've set it, i.e., will it get overwritten by anything?

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

Like I said, I'm trying out a lot of stuff at the moment.....just seeing what's what. That's now two methods I know of for doing this.

Thanks, Mochi (and puppy_apprentice).

Cheers!


Mike. :wink:
Last edited by Mike Walsh on Tue 13 Mar 2018, 16:30, edited 1 time in total.

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

#38 Post by drunkjedi »

I am glad it worked.
I was away from home so couldn't test it myself and report, all I had was snippet from memory.

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

#39 Post by Mike Walsh »

Hiya, dj.

Yes, it certainly does work; nicely, too. As I said in the last post, I thought it had to be written in 'Swallow' format for that side of the tray. Don't know why I thought that, but.....there you go. :lol:

Now I know differently! Cheers.


Mike. :wink:

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

#40 Post by greengeek »

Sounds like a good tip to be included in the newsletter don'cha think Mike?
:-)
Attachments
LongWayHome.jpg
(55.83 KiB) Downloaded 165 times

Post Reply