From 728ec6bd120e493e4042c664e1ec97ec7019e81d Mon Sep 17 00:00:00 2001 From: "Matthias S. Benkmann" Date: Thu, 31 Jul 2025 21:46:46 +0200 Subject: [PATCH] Contrib: Generate (sub)menus from external scripts. Includes example of a removable drive un/mounter. --- contrib/index.html | 5 + contrib/scripts/notionmount.pl | 205 ++++++++++++++++++++++ contrib/scripts/scripted_dynamic_menu.lua | 46 +++++ 3 files changed, 256 insertions(+) create mode 100755 contrib/scripts/notionmount.pl create mode 100644 contrib/scripts/scripted_dynamic_menu.lua diff --git a/contrib/index.html b/contrib/index.html index 0b733aa0e..0d15aec37 100644 --- a/contrib/index.html +++ b/contrib/index.html @@ -111,6 +111,11 @@

Scripts

schedule.lua
Schedule some messages to show up at specified times in the statusbar. +
scripted_dynamic_menu.lua +
Create a submenu from output of an external program every time the + submenu is opened. Example: notionmount.pl + creates a submenu for mounting/unmounting removable drives. +
send_to_ws.lua
Quickly send to another workspace. diff --git a/contrib/scripts/notionmount.pl b/contrib/scripts/notionmount.pl new file mode 100755 index 000000000..91b721b8b --- /dev/null +++ b/contrib/scripts/notionmount.pl @@ -0,0 +1,205 @@ +#!/usr/bin/perl -ls + +# Copyright (c) 2025 Matthias S. Benkmann +# You may do everything with this code except misrepresent its origin. +# PROVIDED `AS IS' WITH ABSOLUTELY NO WARRANTY OF ANY KIND! + +# For use with scripted_dynamic_menu.lua: Creates menu entries to un/mount removable +# drives like USB flash drives. You add it to a Notion menu like this: +# +# submenu("USB", function() return cmd2menu('notionmount.pl -menu') end), +# +# The submenu will look like this +# +# [_] Drive label 1 +# [X] Drive label 2 +# +# The entries with [_] are unmounted and choosing them will mount the drive. +# The entries with [X] are mounted and choosing them will unmount the drive. +# +# Mounting and unmounting is performed with pmount/pumount, so they must be installed. +# +# The script will beep after successful un/mount. +# To hear these beeps you must have a program "beep" in your path. Ubuntu +# has a package "beep" for instance, that installs such a program. +# +# If you want to know when a device is ready to be mounted (because that takes some time +# after plugging it in), you could create a file +# /etc/udev/rules.d/99-usb-beep.rules with the following single line: +# +# ACTION=="add", SUBSYSTEM=="block", KERNEL=="sd*[0-9]", SUBSYSTEMS=="usb", RUN="/lib/udev/beep" +# +# and a shell script /lib/udev/beep with the following contents: +# #!/bin/sh +# echo $'\a' >/dev/console + + +use strict; +use warnings; + +use Cwd; + +#main() +{ +our ($help, $mount, $unmount, $menu); +my $USAGE="Usage: \n$0 -menu\n" . +" generates ouput for Notion WM scripted_dynamic_menu.lua with un/mount commands for USB devices.\n". +"$0 -mount