Passing fvwm variables to external scripts

Greetings! This is my first time using fvwm and I’m loving the raw power to configure my desktop. I’m trying to create a function to take a screenshot and notify the user. I am wondering if it’s possible to pass fvwm variables like the current window id $[w.id] to external scripts? Example I’m adding to the Window-Ops2 menu is

# Menu for top left hand ("close") button on windows
AddToMenu Window-Ops2
	+  "Raise/Lower "   RaiseLower
	+  "Iconify "       Iconify
	+  "(Un)Stick "     Stick
	+  ""              Nop
	+  "Delete "        Delete
	+  "Close "         Close
	+  "Destroy "       Destroy
  +  ""              Nop
	+  "Take Screenshot " Exec exec $[FVWM_USERDIR]/.local/bin/savescreenshot $[w.id]

And if anyone is interested, here is the trivial bash script I cobbled together in an attempt to take the screenshot.

#!/bin/bash
#set -x
# use -root for window_id if not specified
if [ $# -ne 1 ]; then
  argument="-root"
else
  argument="-id $1"
fi
type xwd >/dev/null 2>&1 || { echo >&2 "This script requires xwd but it's not installed.  Aborting."; exit 1; }
type magick >/dev/null 2>&1 || { echo >&2 "This script requires magick but it's not installed.  Aborting."; exit 1; }
type zenity >/dev/null 2>&1 || { echo >&2 "This script requires zenity but it's not installed.  Aborting."; exit 1; }
test -e ~/Pictures || mkdir -p ~/Pictures
file="$HOME/Pictures/$(date '+%Y%m%d_%H%M%S')_screenshot"
sleep .1
xwd $argument | magick xwd:- $file.png
zenity --info --text "Screenshot saved to $file.png"

What you have is possible, the issue is just when variable expansion happens. In a menu it happens at the time the menu is created. So you need to write a simple wrapper function, because in functions it happens at the time the function is run.

DestroyFunc MyScreenshot
AddToFunc MyScreenshot
+ I Exec exec $[FVWM_USERDIR]/.local/bin/savescreenshot $[w.id]

Then in your menu you just need to call that function.

+  "Take Screenshot " MyScreenshot
1 Like

Thanks for the suggestion, it worked perfectly! cheers :beers: