Disk mounter script optimization

Hello guys!

I did a script that I swallow in a fvwnbuttons, each buttons is linked to a mount (mouse 1) ou unmount (mouse 3) action for a mountpoint specified in fstab. The aim of the script is then just to change the displayed icon according to the state of the filesystem (mounted or not). Every script takes approximately 5 Mb of Ram and since I did that I got an increase in the cpu ressources consumption (I use it for 7 different mountpoints…). The script check every second the state of the filesystem and then changes or doesn’t change the displayed icon.

So I would like to have the script being executed only when I click on the button! Any idea about how to do that??

Here is the script (one of them):

#####################begin#################
# Usage: Module FvwmScript path/to/FvwmScript-Mount-xxxxx
# state=0: unmounted, =1: mounted
#

WindowTitle {FvwmScript-Mount-Sounds}
WindowSize 24 24
Colorset 10

Init
 Begin
	Set $state_prev=-1
 End

PeriodicTasks
  Begin 
    Set $state=(GetOutput {cat /etc/mtab|grep -c sounds} 1 -1)

	  
    #ChangeTitle 1 $state

    If $state==$state_prev Then
    Begin
      #	do nothing
    End	
    Else
    Begin
      Set $state_prev=$state
      Set $scale=$state
      Set $icon= mount/ $scale .png
      #ChangeTitle 1 $icon
      ChangeIcon 1 $icon
    End
  End

Widget 1
Property
 Position 0 0
 Size 24 24
 Type ItemDraw
 Flags NoReliefString Center
Main
 Case message of
  SingleClic :
  Begin
  End
End

###################end########################

and I call it in a Fvwmbuttons module like that:

Sounds button.

*FvwmButtons-MOUNT: (1x1, Size 24 24,
Action (Mouse 1) Exec exec mount /mnt/sounds,
Action (Mouse 3) Exec exec umount /mnt/sounds,
Swallow (Close, Respawn) “FvwmScript-Mount-Sounds”
‘Module FvwmScript $[HOME]/.fvwm/FvwmScript-Mount-Sounds’)

also, if I click on mouse 1 with an already mounted filesystem, the error-message is recorded in my .xsession-errors file, how can I avoid that?

Best regards, Brice

[color=red]Edited by theBlackDragon:
–> Added [code ][/code ] tags to inrease readability.[/color]

You only want the script to run when you press a particular mouse button in FvwmButtons? Is that correct?

– Thomas Adam

Yes that’s it!

I want the script to be run only when I click on a button with the mouse!

Brice