Page 1 of 1

Yad sytem tray right click menu

Posted: Wed 31 Oct 2012, 15:05
by stu91
Here is an example script of a yad system tray right click menu:

Image

Code: Select all

#!/bin/bash
## yad simple system tray right click menu ##
## menu file example in plain text file name!command ##
#Terminal!urxvt
#Paint!mtpaint

## Application menu file ###############################################

GET_MENU="$@"

########################################################################

function START_MENU () {

## MENU items ##########################################################

MENU_ITEMS="` cat "$GET_MENU" | tr '\n' '|' | sed '$s/.$//' `"

## Defaults ############################################################

TRAY_ICON="/usr/share/icons/hicolor/24x24/apps/yad.png"
POPUP_TEXT="system tray menu"
PIPE_FIFO=$(mktemp -u /tmp/menutray.XXXXXXXX)

## Action on left mouse click ###########################################
  function LEFT_CLICK () {
	exec 3<> $PIPE_FIFO
    echo "quit" >&3
    rm -f $PIPE_FIFO
}
  
  export -f LEFT_CLICK
  export PIPE_FIFO

## 1 Create PIPE_FIFO file #############################################
  mkfifo $PIPE_FIFO

## 2 Attach a filedescriptor to this PIPE_FIFO #########################
  exec 3<> $PIPE_FIFO
 
## 3 Run yad and tell it to read its stdin from the file descriptor ####
GUI=$(yad --notification --kill-parent --listen \
--image="$TRAY_ICON" \
--text="$POPUP_TEXT" \
--command="bash -c LEFT_CLICK" <&3 ) & 

## 4 Write menu to file descriptor to generate MENU ####################
 echo "menu:$MENU_ITEMS" >&3
}

## Check if menu file is provided ######################################
 
  if [ -z "$GET_MENU" ]; then 
  echo "traymenu usage: $0 /path/to/menu/file" && exit
  else
  START_MENU
  fi

######################################################################## 
Tray icon and popup text can be customised in script:
TRAY_ICON=
POPUP_TEXT=


Usage: is with a separate menu file which contains menu item name ! menu item command (see below, left is name - right is command - menu order top is first)

Code: Select all

Terminal! urxvt
Paint! mtpaint
Text Edit! geany
Media! gnome-mplayer
Home! rox /root
Sda2! rox /mnt/sda2
To run: /path/to/script /path/to/menu/file

cheers.

Posted: Thu 01 Nov 2012, 15:51
by don570
It worked when I tried it in Precise.

It would be more useful if running the terminal command
wasn't necessary each time the menu file was changed.

__________________________________________

Posted: Thu 01 Nov 2012, 17:39
by stu91
don570 wrote:It worked when I tried it in Precise.

It would be more useful if running the terminal command
wasn't necessary each time the menu file was changed.

__________________________________________
Hi don570,
Thanks for testing and feedback 8)

Im not quite sure i understand what you mean in the second lines of your post, could you give an example?

You do not need to use a menu file instead the menu could be put in the script by changing:

GET_MENU="$@"

to

GET_MENU='Terminal! urxvt
Paint! mtpaint
Text Edit! geany
Media! gnome-mplayer
Home! rox /root
Sda2! rox /mnt/sda2
'

Posted: Thu 01 Nov 2012, 18:17
by don570
I was referring to a menu editor. (A couple already exist for Puppy)


So the user filled in fields rather than create a file.
Geany can open a document for example ---> so two fields
would be needed for each app

and maybe a button to click so previous tray icons quit.

Probably too much work.

__________

Yad sytem tray right click menu

Posted: Sat 10 Nov 2012, 15:01
by L18L
Hi stu9x

I have have been playing with your script

TRAY_ICON="/usr/share/doc/puppylogo48.png"
POPUP_TEXT="one of my special mini menus "


Using
GET_MENU='Terminal! urxvt
Paint! mtpaint
'
MENU_ITEMS= has to be changed to
MENU_ITEMS="` echo "$GET_MENU" | tr '\n' '|' | sed '$s/.$//' `"

Having different TRAY_ICON and POPUP_TEXT for each menu now
Launched by Startup in precise

Very cool 8)
though most of that code is "all Greek" to me

Posted: Wed 14 Nov 2012, 20:39
by technosaurus
the way I got around all of the complexity in sit (simple icon tray) was to use user defined commands for the left and right click menus ... these can be simulated in gtkdialog by setting window-placement="2" in the <window> tag (I forget what it is in yad, but most dialog apps including Xdialog have similar near mouse window positioning abilities)
Also in sit all tooltips and icons get automagically refreshed if the image or tooltip file is changed and since the user defines the click actions, those can be changed on the fly too. so changing behavior is as simple as copying one icon over another icon, echoing to a tooltip text file or modifying the right/left-click action script/function/executable. The number of icons is unlimited, so AFAIK sit covers 99% of needs for creating tray apps and is only ~5kb

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

There are also a lot of tips scattered throughout the thread for generating simple yet useful svg images within scripts as well as some examples for parsing data in a way that is useful for tray apps.

Posted: Mon 09 Sep 2013, 09:40
by Argolance
Bonjour,
This Yad sytem tray right click menu is great and very useful.
Thanks!

I would like to know if it is possible to get small icons at the head of the entries of this right click menu? And if yes, how?
I succeeded in making such a menu using gtkdialog and by setting window-placement="2" in the <window> tag but:
  • - the bottom of the menu is hidden behind the JWM task bar.
    - the icon is in the quick launch part of the JWM task bar
:(

Cordialement.

Posted: Mon 09 Sep 2013, 10:55
by mikeb
oops I wish I could read but updating the menu is just a case of echoing to the pipe on >3 by whatever convenient means

mike

Posted: Mon 09 Sep 2013, 11:07
by Argolance
oops I wish I could read but updating the menu is just a case of echoing to the pipe on >3 by whatever convenient means
Sorry, I don't understand what you mean! :oops:
Is it to say that such a menu exists, but simplier, without the "echoing to the pipe on >3". If yes where could I find it?

Cordialement.

Posted: Mon 09 Sep 2013, 11:49
by mikeb
Sorry to confuse It was more a general reply to yad usage plus I messed up my post and quickly edited it... hence the 'oops'
It would be more useful if running the terminal command
wasn't necessary each time the menu file was changed.
rather than an answer to your question Argolance.

As for Icons the yad wiki might be helpful to you

http://code.google.com/p/yad/wiki/NotificationIcon

regards

Mike

Posted: Mon 09 Sep 2013, 12:10
by Argolance
OK, thanks!