SetEnv change in context

Hi!

I have a complex problem…

In my config i set
SetEnv $mpd_host localhost

And i use this variable on many places to reach my mpd-player.

But now i want to change this variable, while Fvwm is running to reach another mpd-host to remote-controll this one.
I made a menu which is feed from a shell-skript with avahi-browse-output to have always actual mpd-hosts in my menu. But how can i set this variable new, that the whole mpd-context can use the new one?
SetEnv in the menu doesn’t work…

scientific

Can you post your menu?

Another way is from your shell script with FvwmCommand. But you have to start the module before using]
Module FvwmCommandS
[/code]
Then you can send the SetEnv command from your script FvwmCommand 'SetEnv mpd_host foo'

TF

DestroyMenu recreate mpd-outputs
AddToMenu mpd-outputs “MPD-Outputs $[mpd_host]” Title
PipeRead $[HOME]/.fvwm/scripts/fvwm-menu-mpd-outputs $mpd_host $mpd_port

and this script:

#!/bin/bash

export MPC="/usr/bin/mpc"
export CON="-h $mpd_host -p $mpd_port"
IFS=“§”

/usr/bin/mpc -h $mpd_host -p $mpd_port outputs |sed -e ‘s/^Output //’ -e ‘s/ is //’ -e ‘s/enabled/1/’ -e ‘s/disabled/0/’ -e ‘s/[()]/§/g’|while read i j k
do
if [ $k -eq 1 ]
then
echo “+ %noicon-green.png%”$j" Exec exec $MPC disable $i"
else
echo “+ %noicon-red.png%”$j" Exec exec $MPC enable $i"
fi
done

avahi-browse --all -t --resolve -p|sed -n ‘/^=.*.IPv4.*Music Player Daemon/p’|awk -F";" ‘{print “+ “”$(NF-3)” - “$(NF-2)”" Exec FvwmCommand “SetEnv mpd_host “$(NF-2)””"}’

And this WORKS NOW!!! YEAH!!! Thank you!!!

I’ve seen a simmilar solution for my problem. And the reason, why it didn’t work for me have beent the ticks befor SetEnv and in the end… :slight_smile:

Thanks a lot

scientific

Ok… next problem…

I wrote an Applet which i swallow in my Button. This is a Fvwm-Script, an i use ther also this environment-variable $mpd_host.

A line of this script is:
Set $song = (GetOutput {exec mpc -h $mpd_host -p $mpd_port current} 1 -1)

and this applet use always the mpd_host from when it starts. But when i change the mpd-host, i want to show the actual song from the choosen mpd-host… so i need a reset/update of mpd_host in the applet.

Do i have to use SendToModule or something else?

scientific

You can check your two SetEnv variables $[mpd_host] and $[mpd_port] periodically over the PeriodicTasks loop.
Create two internal variables for $mpd_host and $mpd_port in Init]Set $mpd_host = (GetOutput {echo $[mpd_host]} 1 -1)
Set $mpd_port = (GetOutput {echo $[mpd_port]} 1 -1)[/code]
now you can check them every seconds in the PeriodicTasks loop if there’s a changeSet $tmp_mpd_host = (GetOutput {echo $[mpd_host]} 1 -1) If $mpd_host <> $tmp_mpd_host Then $mpd_host = $tmp_mpd_host Set $tmp_mpd_port = (GetOutput {echo $[mpd_port]} 1 -1) If $mpd_port <> $tmp_mpd_port Then $mpd_port = $tmp_mpd_port

This Code doesn’t work.
First, you’ve forgotten “Set”

Set $tmp_mpd_host = (GetOutput {echo $[mpd_host]} 1 -1) If $mpd_host <> $tmp_mpd_host Then Set $mpd_host = $tmp_mpd_host Set $tmp_mpd_port = (GetOutput {echo $[mpd_port]} 1 -1) If $mpd_port <> $tmp_mpd_port Then Set $mpd_port = $tmp_mpd_port

But it doesn’t work already. $tmp_mpd_host is “$[mpd_host]” and not the value of the environment variable.

The solution in the postings before changes the value inside fvwm of $mpd_host, but not in the shell. And this script asks the shell for $fvwm_host…

scientific

uups :blush: … sh*** happens :wink:

Then change it]Set $tmp_mpd_host = (GetOutput {echo $mpd_host} 1 -1)
If $mpd_host <> $tmp_mpd_host Then
Set $mpd_host = $tmp_mpd_host[/code]

WHERE? In no previous post you mention ‘$fvwm_host’. So …
If you want to change a value in the shell from inside FvwmScript]
Do {exec foo=bla}
[/code]
Sorry, I don’t understand it …

I already tryed also this solution. The effect is… nothing. mpd_host stays on the value, when the script was initialized.

Ok. I try to do my best to explain my problem.

I have a mpd running on my localhost, and another one on another computer. And i want to control these two mpds with a small Applet and some Buttons in FvwmButton.

One of the Control-Buttons in FvwmButton is:
*FvwmButton: (3x2 Frame 0, Icon player_stop.png Action Exec exec echo -e "stop\\nclose"|nc $mpd_host $mpd_port)

To show, which song is acutally played in the mpd is solved in the script, we are talking about.

And i can choose the mpd-host in a menue with some of these lines:

  • “pluto.local - 192.168.0.100” Exec FvwmCommand “SetEnv mpd_host 192.168.0.100”; FvwmCommand “SetEnv mpd_port 6600”

When i choose an mpd-host with this menu, the Control-Button works and controls the right mpd-host, but i want to pass the variable mpd_host to the script. And this doesn’t work.
The code you give me, always passes the $mpd_host when the script was initialized. What the problem is… I don’t know. Which Environment ist valuable for the script?

I think the code in the periodic task-section takes the environment from the subshell of the script
Set $tmp_mpd_host = (GetOutput {echo $mpd_host} 1 -1)
and not from fvwm itself. When the script gets initialized, it takes the environment from the father-shell - fvwm itself.

Do you now understand, what i mean? If not, i try to explain it better again. Im not a nativ-english-speaker… :wink:

scientific

Ah, now I understand it better ^^

I am at work at the moment, so I haven’t any time to post you something. As I am back at home I try it again.
Could you post your FvwmScript for completeness and your complete menu, too?

Thanks,
TF

Ok. I see… :slight_smile:

To post this, it’s a lot of stuff…

Maybe it could be a possible way, to launch a Script periodically, which returns the current value of mpd_host in the environment of fvwm, and pass this value to the script.

The menu:

DestroyMenu recreate mpd-outputs
AddToMenu mpd-outputs "MPD-Outputs $[mpd_host]" Title
PipeRead $[HOME]/.fvwm/scripts/fvwm-menu-mpd-outputs

The bash-script fvwm-menu-mpd-outputs:

The output of this script (= the Menu above)

You see, i can also activate/deactivate the outputs of the current mpd-players, choosen in the second part of the menu. And the list is always actual. This part works fine! (thanks to you, for your hints at the begin of this thread!!!)

The control-part in FvwmButton (Called FvwmShelf in my config)

The Variable $[CS] is the colorset.

And now the FULL script “FvwmApplet-MpdSongInfo”

This script should be updated during it runs to the current mpd-host set with the menu above. But always it shows the infos from the mpd-player when the script was started…

Ok, i solved the Problem. I don’t know, if it is a good solution. But it works.

I swallow this Applet respawned in the Button. On changing the mpd-host, i kill this Applet, and fvwm respawns it with the new environment-variables.

Now it works. I’m happy :slight_smile:

The menu-entry now is this:

  • “pluto.local - 169.254.0.2” Exec FvwmCommand “SetEnv mpd_host 169.254.0.2”; FvwmCommand “SetEnv mpd_port 6600”; FvwmCommand “KillModule FvwmScript FvwmApplet-MpdSongInfo”

And in FvwmButton:
*FvwmShelf: (22x2, Frame 0, Swallow (Respawn)“FvwmApplet-MpdSongInfo” FvwmScript FvwmApplet-MpdSongInfo $[CS] )

But if you know another Method to pass the changed value to this script, let me know.

Thx for all your help

scientific

Ok,

I’ve tested it with the following:
First I set two Env vars within FvwmConsole SetEnv mpd_host "192.168.20.10" SetEnv mpd_port 6000
and start my test script]
WindowTitle {FvwmScript-Testem}
WindowSize 110 50
Font “xft:DejaVu Sans:size=8”

Init
Begin
Set $mpd_host = (GetOutput {echo $mpd_host} 1 -1)
ChangeTitle 1 $mpd_host
Set $mpd_port = (GetOutput {echo $mpd_port} 1 -1)
ChangeTitle 2 $mpd_port
End

PeriodicTasks
Begin
Set $new_mpd_host = (GetOutput {echo $mpd_host} 1 -1)
Do {echo new_mpd_host:}$new_mpd_host
If $mpd_host <> $new_mpd_host Then
Begin
Set $mpd_host = $new_mpd_host
ChangeTitle 1 $mpd_host
End
Set $new_mpd_port = (GetOutput {echo $mpd_port} 1 -1)
If $mpd_port <> $new_mpd_port Then
Begin
Set $mpd_port = $new_mpd_port
ChangeTitle 1 $mpd_port
End
End

mpd host

Widget 1
Property
Type ItemDraw
Size 100 20
Position 5 5
Flags NoFocus NoReliefString Left
Main
Case message of
End

mpd port

Widget 2
Property
Type ItemDraw
Size 100 20
Position 5 30
Flags NoFocus NoReliefString Left
Main
Case message of
End[/code]
After that I changed $[mpd_host] to SetEnv mpd_host "192.168.20.20" and … nothing happens.

But after restarting the script it shows the correct IP. I think the environment will be frozen for the script and so it can’t recognize a SetEnv change.

Then I changed the script]WindowTitle {FvwmScript-Testem}
WindowSize 110 50 # Taille
Font “xft:DejaVu Sans:size=8”

Init
Begin
Set $mpd_host = (GetOutput {echo $mpd_host} 1 -1)
Set $new_mpd_host = $mpd_host
ChangeTitle 1 $mpd_host
Set $mpd_port = (GetOutput {echo $mpd_port} 1 -1)
Set $new_mpd_port = $mpd_port
ChangeTitle 2 $mpd_port
End

PeriodicTasks
Begin
Do {echo new_mpd_host:}$new_mpd_host
If $mpd_host <> $new_mpd_host Then
Begin
Set $mpd_host = $new_mpd_host
ChangeTitle 1 $mpd_host
End
If $mpd_port <> $new_mpd_port Then
Begin
Set $mpd_port = $new_mpd_port
ChangeTitle 1 $mpd_port
End
End

mpd host

Widget 1
Property
Type ItemDraw
Size 100 20
Position 5 5
Flags NoFocus NoReliefString Left
Main
Case message of
1 :
Begin
Set $new_mpd_host = (LastString)
End

2 :
Begin
	Set $new_mpd_port = (LastString)
End

End

mpd port

Widget 2
Property
Type ItemDraw
Size 100 20
Position 5 30
Flags NoFocus NoReliefString Left
Main
Case message of
End[/code]
and use ‘SendToModule’ to inform the script that mpd_host is changed]SetEnv mpd_host “192.168.20.10”
SendToModule FvwmScript-Testem SendString 1 1 $[mpd_host][/code]Now it works :slight_smile:

To use it you should:

  1. choose one of your widgets in FvwmApplet-MpdSongInfo which will get the messages e.g. widget 1 :wink:
  2. change your avahi line in the script]
    avahi-browse --all -t --resolve -p|sed -n ‘/^=.*.IPv4.*Music Player Daemon/p’|awk -F";" ‘{print “+ “”$(NF-3)” - “$(NF-2)”" FuncSetNewMpd “$(NF-2)” “$(NF-1)”"}’
    [/code]3) Create the function to set the new values and inform the script[code]
    DestroyFunc FuncSetNewMpd
    AddToFunc FuncSetNewMpd
  • I SetEnv mpd_host $0
  • I SetEnv mpd_port $1
  • I SendToModule FvwmApplet-MpdSongInfo SendString 1 1 $[mpd_host]
  • I SendToModule FvwmApplet-MpdSongInfo SendString 1 2 $[mpd_port][/code]
    Jup, that’s it I think.

Hope it works ^^
Cheers,
TF

Hi!

YES! I had to deal a lot to recognize, how my script works exactly… but now i’ve got it.

I had to change some lines from

to

And now it works like a charm. :slight_smile:

Thank you so much!!!

scientific

Ok, one problem more…

My applet works almost like a charm… BUT

I have a function defined to change the Icons of the control-Buttons in FvwmButton.

The function is:

DestroyFunc CHANGE_ICON
AddToFunc CHANGE_ICON
+ I SendToModule FvwmShelf ChangeButton $0 Icon $1

And the call from the Script is:

[code]

Set $MPC = {exec /usr/bin/mpc -h }$mpd_host{ -p }$mpd_port
Set $cmd = $MPC{ status}
Set $cmd = $cmd{|awk ‘/volume/’|sed -e ‘s/volume: *//’ -e ‘s/%//’}
Set $volume = (GetOutput $cmd 1 1)

 If $volume == 0 Then
Do {CHANGE_ICON mpdVol audio-volume-muted.png}
 If $volume > 0 Then
Do {CHANGE_ICON mpdVol audio-volume-low.png}
 If $volume >= 33 Then
Do {CHANGE_ICON mpdVol audio-volume-medium.png}
 If $volume >= 66 Then
Do {CHANGE_ICON mpdVol audio-volume-high.png}[/code]

And the Line for the MPD-Volume-Button in FvwmButton is:

	*FvwmShelf: (4x2 Frame 0, Id "mpdVol", Icon stock_volume.png Action (Mouse 4) `Exec exec /usr/bin/mpc -h  $mpd_host -p $mpd_port volume +5 > /dev/null`, \
	Action (Mouse 5) `Exec exec /usr/bin/mpc -h $mpd_host -p $mpd_port volume -5 > /dev/null`)

When i change the volume from localhost, the icon changes correctly.
But when i change the volume from remote, i get a error-message on the computer, where the volume should be changed.

[fvwm][ComplexFunction]: <<ERROR>> Grab failed in function CHANGE_ICON mpp player_play.png, unable to execute immediate action

But the volume changes correct…

And in the .xsession-error is also this error:

[code]** (gnome-alsamixer:21241): WARNING **: gam_toggle_get_state (). No idea what to
do for mixer element “Line Jack Mode”!

** (gnome-alsamixer:21241): WARNING **: gam_toggle_get_state (). No idea what to
do for mixer element “IEC958 Playback Source”!

** (gnome-alsamixer:21241): WARNING **: gam_toggle_get_state (). No idea what to
do for mixer element “Input Source”!

** (gnome-alsamixer:21241): WARNING **: gam_toggle_get_state (). No idea what to
do for mixer element “Input Source”![/code]

How i said, the volume changes correctly, only the icon doesn’t get changed from remote. On the remote-host, where the applet is also running, the icon changes correct also.

scientific