Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Wed 18 Oct 2017, 18:39
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Script to put usbdrive icon in systray (Solved)
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 3 [45 Posts]   Goto page: 1, 2, 3 Next
Author Message
nilsonmorales


Joined: 15 Apr 2011
Posts: 916
Location: El Salvador

PostPosted: Sat 04 Mar 2017, 22:14    Post subject:  Script to put usbdrive icon in systray (Solved)  

The code never ends, but I feel comfortable with version 11, it's just more than I expected, thanks
http://wikisend.com/download/342974/desmontarusbipc11

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

Hello im trying to make a little script using yad that notify me when un/plug a usbdrive device in the systray ( just because somethimes forget unplug when leave )
Currently run a udev rule that notify with sound when un/plug, here the example.
/etc/udev/rules.d/90-sonidos_usb.rules
Quote:
DRIVER=="usb", ACTION=="add", RUN+="/usr/local/bin/hotplug_usbsounds +"
SUBSYSTEM=="usb", ACTION=="remove", RUN+="/usr/local/bin/hotplug_usbsounds -"

/usr/local/bin/hotplug_usbsounds
Code:
#!/bin/sh
DIR="/usr/share/sounds"
CMD="aplay"
case "$1" in
   +)
      $CMD $DIR/insert.wav &
   ;;
   -)
      $CMD $DIR/remove.wav &
   ;;
esac

then in terminal
Code:
udevadm control --reload

everything is ok at this point, my problem is when try to setting the icon in the systray, here's the script.
Code:
#!/bin/sh -x

ICON=/usr/local/lib/X11/pixmaps/usbdrv48.png
TOOLTIP="Botón Izquierdo: Actualizar | Botón Derecho: Menú"
mkfifo /tmp/01
exec 3<> /tmp/01

function func_menu() {
   exec 3<> /tmp/01
   # Obtener lista de unidades de almacenamiento montadas
   LISTSDX=($(df | grep /sd | cut -f1 -d ' '))

   for DRIVE in ${LISTSDX[@]}; do
   # Comprobar si los dispositivo de la lista son USB. True: Crear menu. False: Remover de la lista
      udevadm info -q path -n $DRIVE | grep usb && MENUCMD+="⏏ Desmontar $DRIVE "'!'"umount $DRIVE|" || LISTSDX=(${LISTSDX[@]/$DRIVE})
   done

   if [ -z "$LISTSDX" ];then
      echo "menu:No hay unidades usb montadas|actualizar!bash -c func_menu!gtk-refresh" >&3
   else
      echo "menu:$MENUCMD actualizar!bash -c func_menu!gtk-refresh" >&3
   fi
}

export -f func_menu

yad --text="$TOOLTIP" --notification --command="bash -c func_menu" --image=$ICON --listen <&3 &
func_menu

I would like that script to show an icon in systray when I plug my usbdrive, and if possible showme some kind of info like mount point, space left, i dont know, mount/umount would be great.
Please help me, thanx in advance
PD: My english is not very good looking

_________________
My blog | | Github



Last edited by nilsonmorales on Fri 24 Mar 2017, 00:09; edited 2 times in total
Back to top
View user's profile Send private message 
wow

Joined: 29 Jun 2006
Posts: 1034
Location: Peru

PostPosted: Sun 05 Mar 2017, 01:49    Post subject:  

Cambios, ahora actualiza el menú luego de desmontar y muestra un mensaje con yaf-splash.

Code:

#!/bin/sh

ICON=/usr/local/lib/X11/pixmaps/usbdrv48.png
TOOLTIP="Botón Izquierdo: Actualizar | Botón Derecho: Menú"

PIPE=$(mktemp -u --tmpdir ${0##*/}.XXXXXXXX)

mkfifo $PIPE
exec 3<> $PIPE

export PIPE

function func_menu() {
   exec 3<> $PIPE
   # Obtener lista de unidades de almacenamiento montadas
   LISTSDX=($(df | grep /sd | cut -f1 -d ' '))

   for DRIVE in ${LISTSDX[@]}; do
   # Comprobar si los dispositivo de la lista son USB. True: Crear menu. False: Remover de la lista
      udevadm info -q path -n $DRIVE | grep usb && MENUCMD+="⏏ Desmontar $DRIVE "'!'"bash -c 'func_umount $DRIVE'|" || LISTSDX=(${LISTSDX[@]/$DRIVE})
   done

   if [ -z "$LISTSDX" ];then
      echo "menu:No hay unidades usb montadas|actualizar!bash -c func_menu!gtk-refresh" >&3
   else
      echo "menu:$MENUCMD actualizar!bash -c func_menu!gtk-refresh" >&3
   fi
}

function func_umount() {
   #Desmontar
   umount $1
   ret=$?
   [[ $ret -eq 0 ]] && CMDMSGTXT="USB Flash $1 fue desmontado" || CMDMSGTXT="Error desmontando $1 código: $ret"
   #Mostrar ventana de información
   /usr/lib/gtkdialog/box_splash -close box -timeout 3 -placement bottom-right -bg black -fg white -text "$CMDMSGTXT"
   #Actualizar menú
   func_menu
}

export -f func_menu func_umount

yad --text="$TOOLTIP" --notification --command="bash -c func_menu" --image=$ICON --listen <&3 &
func_menu

_________________

Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1366
Location: Japan

PostPosted: Sun 05 Mar 2017, 01:52    Post subject: Re: Help with systray icon usbdrive script  

nilsonmorales wrote:
everything is ok at this point
Not for me, but I wonder if you really need this

Quote:
I would like that script showme a icon in systray when plug my usbdrive, and if possible showme some kind of info like mount point, space left, i dont know, mount/umount would be great.
When you plug in your USB drive, it is still unmounted. I don't think that you can get this kind of information without mounting the drive.

I also don't know how you expect yad to handle the insertion event. Even if you get it to work you would need to keep yad running all the time. Seems pretty wasteful. Why not hook it to some of Puppy's already existing system events?

Just an idea: edit /usr/local/pup_event/frontend_funcs and find add_pinboard_func().
Originally the function adds an icon to the desktop whenever a new drive is plugged in. You could add some code that plays a sound and puts an icon into the tray. Clicking on the tray icon will remove it, but you could as well add other commands.
    add_pinboard_func() { #needs ONEDRVNAME, DRV_CATEGORY, FSTYPE
    if [[ $DRV_CATEGORY == usbdrv ]]; then
    aplay /usr/share/sounds/ok.wav
    ICON=/usr/local/lib/X11/pixmaps/usbdrv48.png
    TOOLTIP="USB drive added at /dev/$ONEDRVNAME"
    yad --text="$TOOLTIP" --notification --image=$ICON &
    fi

    echo "<?xml version=\"1.0\"?>
    <env:Envelope xmlns:env=\"http://www.w3.org/2001/12/soap-envelope\">
Back to top
View user's profile Send private message 
nilsonmorales


Joined: 15 Apr 2011
Posts: 916
Location: El Salvador

PostPosted: Sun 05 Mar 2017, 22:22    Post subject:  

thanks wow your script works well
MochiMoppel you are right, i can't have information without mount the drive, i just need the icon in systray because i always forget unplug the usb, and i like my pinboard without drive icons, i think have information in the systray is better than have in the pinboard, your idea is great. ill test and report later.

_________________
My blog | | Github


Back to top
View user's profile Send private message 
wow

Joined: 29 Jun 2006
Posts: 1034
Location: Peru

PostPosted: Mon 06 Mar 2017, 02:51    Post subject:  

Quote:
and if possible showme some kind of info like mount point, space left, i dont know, mount/umount would be great.

Code:
yad --notification --text Pmount --command pmount --image "/usr/local/lib/X11/pixmaps/usbdrv48.png"
Back to top
View user's profile Send private message 
wow

Joined: 29 Jun 2006
Posts: 1034
Location: Peru

PostPosted: Thu 09 Mar 2017, 21:55    Post subject: Re: Script to put usbdrive icon in systray  

nilsonmorales wrote:
... notify with sound when un/plug

Done.
Code:
SND_CMD=aplay # Cambiar a "echo" para desactivar/Change to "echo" to disable
# Reemplazar por cualquier otro archivo de sonido/Replace sound file for whatever you want
SND_ADD="/usr/share/sounds/bark.au" # conectar/connect
SND_REM="/usr/share/sounds/2barks.au" # desconectar/disconnect

nilsonmorales wrote:
... show an icon in systray when I plug my usbdrive, and if possible showme some kind of info like mount point, space left, i dont know, mount/umount

Done.

Work in progress...

Icon and menu:

Notifications: echo or gxmessage or yaf-splash or notify-send
Code:
# Establecer el comando para las ventanas de información/notificación.
# Set which command will be used for notitications
MSG_CMD="echo"
[ "$(which gxmessage)" ] && MSG_CMD="gxmessage -borderless -nofocus -bg black -fg white -timeout 3"
[ "$(which yaf-splash)" ] && MSG_CMD="yaf-splash -close box -timeout 3 -placement bottom-right -bg black -fg white -text"
[ -e "/usr/lib/gtkdialog/box_splash" ] && MSG_CMD="/usr/lib/gtkdialog/box_splash -close box -timeout 3 -placement bottom-right -bg black -fg white -text"
[ "$(which yad)" ] && MSG_CMD="yad --no-buttons --borders 10 --skip-taskbar --no-focus --undecorated --timeout-indicator bottom --text-align=left --timeout 5 --geometry=200x50-10-50 --text"
[ "$(which notify-send)" ] && MSG_CMD="notify-send -t 5000 -u normal"

Marcar la línea como comentario para desactivar/Coment out the line you want to disable.
Code:
#[ "$(which notify-send)" ] && MSG_CMD="notify-send -t 5000 -u normal"

Code:
#[ "$(which yad)" ] && MSG_CMD="yad --no-buttons --borders 10 --skip-taskbar --no-focus --undecorated --timeout-indicator bottom --text-align=left --timeout 5 --geometry=200x50-10-50 --text"



Tooltip Text Can be disabled with: -n

Localization. Spanish is the base language.
    Download [pusitray_langpack_english01.zip by tenochslb](working title) attached below or [pusitray_fr.tar.gz by argolance].Extract InsertScriptNameHere.mo rename it and copy/move to /usr/share/locale/en/LC_MESSAGES/
    Say your script is named 'pusitray'(it must be a simple filename without extension like .sh .something), so extract InsertScriptNameHere.mo and rename it to 'pusitray.mo', Now move or copy to your locale folder then start/restart the script.

Code:
cp pusitray.mo /usr/share/locale/${LANG::2}/LC_MESSAGES/


Edit1: [ -e "$PIPE" ] && rm -f "$PIPE"

Edit2:
- Replaced 'guess_fstype' with 'blkid' in DRIVEFS
- Excluded '*initrd*' from list in DRIVESPC
- Added ERROR_FILE to store error messages.

Edit3:
- Check yad version >= 0.19
- Check if its already running
- Added fallback MSG_CMD
- Switched menu order for Mounted devices | Unmounted devices.

Edit4:
- Bugfix: garmin gps sdcard sdb/sdc/etc. instead of sdb1/sdc1/etc.

Edit5:
- Now supports dunst/notify-send
- Hardware info in tooltip text.
- Still in spanish.

Edit6;
- Fixed yaf-splash notitications.

Edit7:
- Added Native Language Support, but Spanish is the base language.
- Fixed volume label only showing first word in the string.
- Attached .zip file with translation to english. Template(InsertScriptNameHere_en.po) translated by tenochslb

Edit8:
- Menu, New layout: Pmount || Device1 Name | Device1 partitions || Device2 Name | Device2 partitions || Actualizar/Reload/Refresh
- Menu: Added button [Device name] to open mount-point(s) if any.

Edit9:
- vfat partitions should now be mounted faster.

Edit10:
- Fixed some typos.
- Fixed: vfat partitions mounting too fast for the menu to update.

Edit11:
- Fixed: puppy boot(usbflash) device is now detected properly.

Version 0.11b (testing): http://murga-linux.com/puppy/viewtopic.php?p=948722#948722

Version 0.10d (stable?):
Code:
#!/bin/bash
TEXTDOMAINDIR="/usr/local/share/locale/" TEXTDOMAIN=${0##*/}
# Parametros de inicio.
case "$1" in
   -n)
    DISABLETOOLTIP="true"
    export DISABLETOOLTIP
    ;;
   -*)
    printf "\n"$"Opciones"":\n\n-n   "$"Desactivar actualizaciones del tooltip \n     al conectar o desconectar unidades usb.""\n\n"
    exit
    ;;
esac

# Establecer el comando para las ventanas de información/notificación.
MSG_CMD="echo"
[ "$(which gxmessage)" ] && MSG_CMD="gxmessage -borderless -nofocus -bg black -fg white -timeout 3"
[ "$(which yaf-splash)" ] && MSG_CMD="yaf-splash -close box -timeout 3 -placement bottom-right -bg black -fg white -text"
[ -e "/usr/lib/gtkdialog/box_splash" ] && MSG_CMD="/usr/lib/gtkdialog/box_splash -close box -timeout 3 -placement bottom-right -bg black -fg white -text"
[ "$(which yad)" ] && MSG_CMD="yad --no-buttons --borders 10 --skip-taskbar --no-focus --undecorated --timeout-indicator bottom --text-align=left --timeout 5 --geometry=200x50-10-50 --text"
[ "$(which notify-send)" ] && MSG_CMD="notify-send -t 5000 -u normal"

# Debug, mostrar en CLI el software para las notificaciones.
printf "\nMSG_CMD=${MSG_CMD%%[[:blank:]]*}\n"

# yad >= 0.19
NOAPP_MSG=$"Necesitas instalar yad 0.19 o superior"
if [ "$(which yad)" ]; then
   YAD_VER="$(yad --version | cut -f 1-2 -d '.')"
   if [ $(echo "$YAD_VER >= 0.19" | bc -l) = 0 ]; then
      exec $MSG_CMD "$NOAPP_MSG"
      exit   
   fi
else
   exec $MSG_CMD "$NOAPP_MSG"
   exit
fi

# Iconos para el systray TRAY_ICON_MNT=UnMounted  TRAY_ICON_MNTD=Mounted
TRAY_ICON_MNT="/usr/local/lib/X11/pixmaps/usbdrv48.png"
TRAY_ICON_MNTD="/usr/local/lib/X11/pixmaps/usbdrv_mntd48.png"
MENU_ICON_PUPPY="/usr/share/pixmaps/puppy/puppy.svg"
MENU_ICON_MNT=list-add
MENU_ICON_MNTD=list-remove
TOOLTIP=$"Botón Izquierdo: Actualizar \nBotón Derecho: Menú"
# Sonidos al conectar y desconectar usb drives.
SND_CMD=aplay # Cambiar a "echo" para desactivar
SND_ADD="/usr/share/sounds/bark.au"
SND_REM="/usr/share/sounds/2barks.au"
ERROR_FILE="/tmp/${0##*/}_error" # Almacenar los mensajes de error del comando: mount
PIPE="/tmp/${0##*/}_tmp" # Archivo para comunicarse con yad

# Debug, mostrar algo de información.
printf "SND_CMD=$SND_CMD\nSND_ADD=$SND_ADD\nSND_REM=$SND_ADD\nERROR_FILE=$ERROR_FILE\nPIPE=$PIPE\n\n"

# Terminar script si existe "$PIPE".
[ -e "$PIPE" ] &&  echo $"Script ya está en ejecución. Saliendo..." && exit
mkfifo "$PIPE"
exec 3<> "$PIPE"

trap 'func_term' SIGINT SIGQUIT SIGTSTP EXIT

export PIPE ERROR_FILE TRAY_ICON_MNT TRAY_ICON_MNTD MENU_ICON_MNT MENU_ICON_MNTD MSG_CMD TOOLTIP

function func_term() { # Limpiar archivos temporales al cerrar el script.
   rm -f "$PIPE" "$ERROR_FILE" "/tmp/pup_event_ipc/block_${0##*/}"
   echo "quit" >&3
   exit
}

function func_menu() {
   echo $"# Generando menú #"
   exec 3<> "$PIPE"
   # Elementos adicionales para el menú.
   MENU_CMD1=$"PMount""!pmount!media-floppy"
   MENU_CMD2=$"Actualizar""!bash -c func_menu!view-refresh"
   # Resetear variables.
   unset -v MENU_MNT MENU_UMNT SEP_MNT SEP_UMNT TOOLTIPDRV MENU_DRV NUM_MNTD
   # Obtener lista de particiones sd* en formato "tamaño|nombre" ejemplo: "4194304|sdb1"
   LISTSDX=($(grep 'sd[a-z]' /proc/partitions | tr -s ' ' | tr ' ' '|' | cut -f 4-5 -d '|')) # "grep 'sd[a-z][0-9]' /proc/partitions" no detecta sdcard en garmin gps (sdb/sdc/etc.)
   # Crear lista de dispositivos de almacenamiento.
   BLOCKDEVICES=($(printf '%s\n' "${LISTSDX[@]//[[:digit:]|]/}" | sort -u))

   for BLOCKDEVICE in ${BLOCKDEVICES[@]}; do
      # Comprobar si los dispositivos de la lista son USB.
      if udevadm info -q path -n /dev/$BLOCKDEVICE | grep usb > /dev/null ; then
         if [ -z "$DISABLETOOLTIP" ]; then
            # Obtener información adicional como fabricante y modelo de la unidad.
            VENDOR=$(cat /sys/block/$BLOCKDEVICE/device/vendor | tr -s ' ')
            MODEL=$(cat /sys/block/$BLOCKDEVICE/device/model | tr -s ' ')
            # Nombre del dispositivo como encabezado de tooltip y menú, luego añadir particiones.
            # Ejemplo: Kingston DT microDuo
            TOOLTIPDRV+="<span font=\"12\"><sub><b>$VENDOR $MODEL</b></sub></span>\n"
            MENU_DRV+="|$VENDOR $MODEL"'!'"bash -c 'func_open $BLOCKDEVICE'"'!'"folder-open|"
         fi
         PARTITIONS=($(printf '%s\n' "${LISTSDX[@]}" | grep $BLOCKDEVICE))
         for PARTITION in ${PARTITIONS[@]}; do
            # Usar blkid para tomar datos de la partición.
            PARTITIONBLKID=$(blkid /dev/${PARTITION#*|})
            if [ "$PARTITIONBLKID" ]; then
               # Asignar: sistema de archivos, tamaño y etiqueta; a variables.
               PARTITIONFS=$(grep -oP 'TYPE="\K[^"]+' <<< $PARTITIONBLKID)
               PARTITIONGB=$(echo "scale=2 ; ${PARTITION%|*} / 1048576" | bc)
               PARTITIONLBL=$(grep -oP 'LABEL="\K[^"]+' <<< $PARTITIONBLKID)
               # df muestra el espacio de almacenamiento usado si la partición está montada.
               PARTITIONSPC=$(df | grep ${PARTITION#*|}[[:blank:]] | tr -s ' ' | cut -f 5-6 -d ' ' | tr ' ' '|')
               # Comprobar si la partición está montada.
               if [ "$PARTITIONSPC" ]; then
                  . /etc/DISTRO_SPECS
                  echo "${PARTITION#*|} $PARTITIONFS $PARTITIONGB GB "$"Montado" # Debug.
                  NUM_MNTD=$[NUM_MNTD + 1] # Cantidad de particiones montadas
                  # Crear un elemento para el menú. Ejemplo: "Desmontar LABEL ‣ sdb1 ‣ vfat ‣ 32 GB ‣ 50% ◔"
                  CHECK_INITRD=$(grep '/initrd/' <<< "$PARTITIONSPC")
                  if [ "$CHECK_INITRD" ] ; then
                     # Puppy boot.
                     MENU_PART="$DISTRO_NAME $DISTRO_VERSION $DISTRO_TARGETARCH ‣ $PARTITIONLBL ‣ ${PARTITION#*|} ‣ $PARTITIONFS ‣ $PARTITIONGB GB ‣ ${PARTITIONSPC%|*} ◔"'!'"bash -c 'func_open ${PARTITION#*|}'"'!'"folder-open|"
                  else
                     MENU_PART=$"Desmontar"" $PARTITIONLBL ‣ ${PARTITION#*|} ‣ $PARTITIONFS ‣ $PARTITIONGB GB ‣ ${PARTITIONSPC%|*} ◔"'!'"bash -c 'func_umount ${PARTITION#*|}'"'!'"$MENU_ICON_MNTD|"
                  fi
                  if [ -z "$DISABLETOOLTIP" ]; then
                     # Puppy boot.
                     [ "$CHECK_INITRD" ] && TOOLTIPDRVICON="◎ $DISTRO_NAME $DISTRO_VERSION $DISTRO_TARGETARCH ‣" || TOOLTIPDRVICON="⏏"
                     TOOLTIPDRV+="<sup> $TOOLTIPDRVICON $PARTITIONLBL ‣ ${PARTITION#*|} ‣ $PARTITIONFS ‣ $PARTITIONGB GB ‣ ${PARTITIONSPC%|*} ◔</sup>\n"
                     # Agregar nueva línea a MENU_DRV. Ejemplo: Kingston DT microDuo
                     #                                          Desmontar LABEL ‣ sdb1 ‣ vfat ‣ 32 GB ‣ 50% ◔
                     MENU_DRV+="$MENU_PART"
                  else
                     # Agregar esta línea a la lista de particiones desmontadas.
                     MENU_UMNT+="$MENU_PART"
                  fi
               else
                  echo "${PARTITION#*|} $PARTITIONFS $PARTITIONGB GB "$"Desmontado" # Debug.
                  MENU_PART=$"Montar"" $PARTITIONLBL ‣ ${PARTITION#*|} ‣ $PARTITIONFS ‣ $PARTITIONGB GB"'!'"bash -c 'func_mount ${PARTITION#*|} $PARTITIONFS'"'!'"$MENU_ICON_MNT|"
                  if [ -z "$DISABLETOOLTIP" ]; then
                     TOOLTIPDRV+="<sup> ⚫ $PARTITIONLBL ‣ ${PARTITION#*|} ‣ $PARTITIONFS ‣ $PARTITIONGB GB</sup>\n"
                     MENU_DRV+="$MENU_PART"
                  else
                     # Agregar esta línea a la lista de particiones montadas.
                     MENU_MNT+="$MENU_PART"
                  fi
               fi
            fi
         done
      else
         # Remover particiones de $BLOCKDEVICE si no es usb.
         LISTSDX=(${LISTSDX[@]/*$BLOCKDEVICE*})
      fi
   done
   
   # Si no existen unidades usb flash ocultar icono.
   if [ -z "$LISTSDX" ];then
      MSG_CMD_TXT=$"No se detectaron unidades usb flash, ocultando icono..."
      YADMENUBODY=""
      echo "visible:false" >&3
      echo "$MSG_CMD_TXT"
      exec ${MSG_CMD/timeout 3/timeout 5} "$MSG_CMD_TXT" &
   # Generar Menú.
   else
      echo "visible:true" >&3 
      # Cambiar icono si no hay nada montado.
      [ -z "$NUM_MNTD" ] && echo "icon:$TRAY_ICON_MNT" >&3 || echo "icon:$TRAY_ICON_MNTD" >&3
      MSG_MENU=$"# Menú generado #"

      if [ -z "$DISABLETOOLTIP" ]; then
         YADMENUBODY="$MENU_DRV"
         echo "$MENU_DRV" > /tmp/menu_drv
         echo "$MSG_MENU"
         TOOLTIPDRV+="<span font=\"1\"> </span>\n$TOOLTIP"
         echo "tooltip:$TOOLTIPDRV" >&3
         echo $"Tooltip generado."
      else
         [ "$MENU_UMNT" ] && SEP_UMNT="|"
         [ "$MENU_MNT" ] && SEP_MNT="|"
         # Remover el último caracter(separador de menú | ) de la variable ${MENU_MNT%|*}
         YADMENUBODY="$SEP_MNT${MENU_MNT%|*}$SEP_MNT$SEP_UMNT${MENU_UMNT%|*}$SEP_UMNT"
         echo "$MSG_MENU"
      fi
      # Actualizar el menú.
      echo "menu:$MENU_CMD1|$YADMENUBODY|$MENU_CMD2" >&3
   fi 
}

function func_mount() {
   mkdir -p "/mnt/$1" &
   # Montar.
   echo $"Montando /dev/$1 en /mnt/$1" &
   MOUNT_CMD="mount"
   # El script "mount" de puppy es lento para montar, usar "mount-FULL" si está disponible.
   [ "$(which mount-FULL)" ] && MOUNT_CMD="mount-FULL"
   case $2 in
      vfat)
         MOUNT_OPS="-t vfat -o iocharset=utf8,umask=000,shortname=mixed,quiet"
         eval $MOUNT_CMD "$MOUNT_OPS" "/dev/$1" "/mnt/$1" 2> "$ERROR_FILE"
         ret=$?
         ;;
      ntfs) 
         MOUNT_OPS="-t ntfs -o nls=utf8,umask=0222"
         eval $MOUNT_CMD "$MOUNT_OPS" "/dev/$1" "/mnt/$1" 2> "$ERROR_FILE"
         ret=$?
         ;;
      *)
         mount -t "$2" "/dev/$1" "/mnt/$1" 2> "$ERROR_FILE"
         ret=$?
         ;;
   esac
   # Actualizar menú.
   func_menu

   if [[ $ret -eq 0 ]]; then
      MSG_CMD_TXT=$"$1 fue montado en /mnt/$1"
      xdg-open "/mnt/$1" &
   else
      MSG_CMD_TXT=$"Error al montar /dev/$1 en /mnt/$1 código:"" $ret $(cat $ERROR_FILE)"
   fi


   echo "$MSG_CMD_TXT"
   # Agregar título a la ventana de información.
   MSG_CMD_TXT1=$"Montando"
   [ "${MSG_CMD%%[[:blank:]]*}" = "yad" ] && MSG_CMD_TXT="<b><big>$MSG_CMD_TXT1</big></b>\n$MSG_CMD_TXT"
   [ "${MSG_CMD%%[[:blank:]]*}" = "notify-send" ] && USE_MSG_CMD_TXT1="1"
   # Mostrar ventana de información.
   if [ "$USE_MSG_CMD_TXT1" ]; then
      exec $MSG_CMD "$MSG_CMD_TXT1" "$MSG_CMD_TXT"
   else
      exec $MSG_CMD "$MSG_CMD_TXT"
   fi
}

function func_umount() {
   # Desmontar.
   echo $"Desmontando /dev/$1" &
   # Determinar punto de montaje.
   MNT_DIR=$(df | grep /dev/$1[[:blank:]] | tr -s ' ' | cut -f 6 -d ' ')
   rox -D "$MNT_DIR" &
   sync
   umount "$MNT_DIR"
   ret=$?
   # Actualizar menú.
   func_menu
   
   [[ $ret -eq 0 ]] && MSG_CMD_TXT=$"$1 fue desmontado" || MSG_CMD_TXT=$"Error al desmontar $1 código:"" $ret"
   echo "$MSG_CMD_TXT"

   MSG_CMD_TXT1=$"Desmontando"
   # Agregar título a la ventana de información.
   [ "${MSG_CMD%%[[:blank:]]*}" = "yad" ] && MSG_CMD_TXT="<b><big>$MSG_CMD_TXT1</big></b>\n$MSG_CMD_TXT"
   [ "${MSG_CMD%%[[:blank:]]*}" = "notify-send" ] && USE_MSG_CMD_TXT1="1"
   # Mostrar ventana de información.
   if [ "$USE_MSG_CMD_TXT1" ]; then
      exec $MSG_CMD "$MSG_CMD_TXT1" "$MSG_CMD_TXT" &
   else
      exec $MSG_CMD "$MSG_CMD_TXT" &
   fi
}

function func_open() {
   # Determinar puntos de montaje.
   MNT_DIR=$(df | grep /dev/$1 | tr -s ' ' | cut -f 6 -d ' ')

   # Abrir carpetas.
   for MOUNTPOINT in ${MNT_DIR[@]} ; do xdg-open "$MOUNTPOINT" ; done
}

export -f func_menu func_mount func_umount func_open func_term

yad --text="$(echo -e $TOOLTIP)" --notification --command="bash -c func_menu" --image="$TRAY_ICON_MNT" --listen --no-middle <&3 &

func_menu

while true; do
   EVENTS=$(pup_event_ipc "block:${0##*/}")
   # Sonido al conectar hardware.
   [ "${EVENTS::3}" = "add" ] && exec $SND_CMD "$SND_ADD" &
   if [ "${EVENTS::3}" = "rem" ]; then
      # Sonido al desconectar hardware.
      exec $SND_CMD "$SND_REM" &
      PUPEVENTREM=($(grep -oP 'rem:\K[^ ]+' <<< $EVENTS))
      for i in ${PUPEVENTREM[@]} ; do
         # Verificar que no queden puntos de montaje activos al desconectar.
         CHECK_MNT=$(df | grep $i[[:blank:]] | tr -s ' ' | cut -f 6 -d ' ')
         if [ "$CHECK_MNT" ]; then
            # Quitar el punto de montaje dejado por el usuario al remover la unidad sin desmontar.
            func_umount $i
            MSG_CMD_TXT=$"CUIDADO, quitar la unidad $i sin desmontar puede crear pérdida de datos o dañar la unidad"
            # Agregar título a la ventana de información.
            MSG_CMD_TXT1=$"Alerta"
            [ "${MSG_CMD%%[[:blank:]]*}" = "notify-send" ] && USE_MSG_CMD_TXT1="1" && MSG_CMD="${MSG_CMD/-u normal/-u critical}"
            [ "${MSG_CMD%%[[:blank:]]*}" = "yad" ] && MSG_CMD="${MSG_CMD/--timeout 5 --geometry=200x50-10-50/--timeout 10 --geometry=200x50-10+50}" && MSG_CMD_TXT="<b><big>$MSG_CMD_TXT1</big></b>\n$MSG_CMD_TXT"

            if [ "$USE_MSG_CMD_TXT1" ]; then
               exec $MSG_CMD "$MSG_CMD_TXT1" "$MSG_CMD_TXT" &
            else
               exec ${MSG_CMD/-timeout 3 -placement bottom-right/-timeout 10 -placement top-right} "$MSG_CMD_TXT"  &
            fi
         fi
      done
   fi
   # Actualizar menu al notificar cambio de hardware.
   func_menu &
done

pusitray_langpack_english01.zip
Description  Extract InsertScriptNameHere.mo(English) rename it and copy/move to /usr/share/locale/en/LC_MESSAGES/
zip

 Download 
Filename  pusitray_langpack_english01.zip 
Filesize  2.78 KB 
Downloaded  49 Time(s) 

_________________


Last edited by wow on Wed 29 Mar 2017, 15:06; edited 16 times in total
Back to top
View user's profile Send private message 
nilsonmorales


Joined: 15 Apr 2011
Posts: 916
Location: El Salvador

PostPosted: Thu 09 Mar 2017, 23:02    Post subject:  

wow wrote:
Quote:
Work in progress...

Hey wow your script runs very good, hide the icon if no usbdevice is plug in the pc, the icon appear immediately when insert my devices, and the list looks great, even open the usb mounted in thunar, everything works ok, thank you for your help, i think is enough to me. look the pic

_________________
My blog | | Github


Back to top
View user's profile Send private message 
wow

Joined: 29 Jun 2006
Posts: 1034
Location: Peru

PostPosted: Fri 10 Mar 2017, 09:21    Post subject:  

Script updated.
http://www.murga-linux.com/puppy/viewtopic.php?p=946888#946888

_________________

Back to top
View user's profile Send private message 
nilsonmorales


Joined: 15 Apr 2011
Posts: 916
Location: El Salvador

PostPosted: Fri 10 Mar 2017, 22:05    Post subject:  

updated script works fine, if some problem appear ill report back.
thank you again.

_________________
My blog | | Github


Back to top
View user's profile Send private message 
wow

Joined: 29 Jun 2006
Posts: 1034
Location: Peru

PostPosted: Sat 11 Mar 2017, 20:17    Post subject:  

Script updated. Small bugfix for device partition sd[a-z] instead of sd[a-z][0-9] like garmin gps sdcard
http://www.murga-linux.com/puppy/viewtopic.php?p=946888#946888

_________________

Back to top
View user's profile Send private message 
nilsonmorales


Joined: 15 Apr 2011
Posts: 916
Location: El Salvador

PostPosted: Sun 12 Mar 2017, 12:19    Post subject:  

testing last script update, everything looks fine.

_________________
My blog | | Github


Back to top
View user's profile Send private message 
wow

Joined: 29 Jun 2006
Posts: 1034
Location: Peru

PostPosted: Tue 14 Mar 2017, 02:54    Post subject:  

And more changes:
http://www.murga-linux.com/puppy/viewtopic.php?p=946888#946888

Notifications:

Tooltip Text

_________________

Back to top
View user's profile Send private message 
wow

Joined: 29 Jun 2006
Posts: 1034
Location: Peru

PostPosted: Tue 14 Mar 2017, 05:31    Post subject:  

Bugfix: yad-splash messages were partially broken with the last update.
http://www.murga-linux.com/puppy/viewtopic.php?p=946888#946888
Back to top
View user's profile Send private message 
corvus


Joined: 12 Jun 2015
Posts: 126
Location: In the peninsula shaped like a boot.

PostPosted: Tue 14 Mar 2017, 07:58    Post subject: Safely remove USB device  

Greetings to all, I would like to propose to add the ability to safely remove the USB device. I personally use, via command line, a script (created by Yan Li in 2009), that need sdparm.
Attached the pet I created with the 64-bit version of sdparm, I also have the 32-bit version.
I hope it can help improve your script wow.
Best Regards.
suspend_usb_drv-1.0-x64.pet
Description 
pet

 Download 
Filename  suspend_usb_drv-1.0-x64.pet 
Filesize  77.09 KB 
Downloaded  33 Time(s) 

_________________
Hoc unum scio, me nihil scire. Socrate
Back to top
View user's profile Send private message 
wow

Joined: 29 Jun 2006
Posts: 1034
Location: Peru

PostPosted: Wed 15 Mar 2017, 21:34    Post subject:  

http://www.murga-linux.com/puppy/viewtopic.php?p=946888#946888

Now with native language support:


Download [pusitray_langpack_english01.zip](working title) (InsertScriptNameHere_en.po=Template translated to english InsertScriptNameHere.pot=Template)attached here.Extract InsertScriptNameHere.mo rename it and copy/move to /usr/share/locale/en/LC_MESSAGES/
Say your script is named 'pusitray'(it must be a simple filename without extension like .sh .something), so extract InsertScriptNameHere.mo and rename it to 'pusitray.mo', Now move or copy to your locale folder then start/restart the script. Example:
Code:
cp pusitray.mo /usr/share/locale/${LANG::2}/LC_MESSAGES/

_________________

Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 3 [45 Posts]   Goto page: 1, 2, 3 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1035s ][ Queries: 14 (0.0131s) ][ GZIP on ]