From e8db349c81d6d6eb35455a72eaae72bce38498c4 Mon Sep 17 00:00:00 2001 From: Daniel Kempkens Date: Sat, 16 Nov 2024 18:56:39 +0100 Subject: [PATCH] pallas: manage EventScripts scripts --- home/hosts/Pallas.nix | 2 ++ home/programs/event-scripts.nix | 41 +++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 home/programs/event-scripts.nix diff --git a/home/hosts/Pallas.nix b/home/hosts/Pallas.nix index 28bb1be..e7e13de 100644 --- a/home/hosts/Pallas.nix +++ b/home/hosts/Pallas.nix @@ -26,6 +26,8 @@ in ../programs/btop.nix + ../programs/event-scripts.nix + ../programs/gallery-dl.nix ../programs/gpg.nix diff --git a/home/programs/event-scripts.nix b/home/programs/event-scripts.nix new file mode 100644 index 0000000..eedb86f --- /dev/null +++ b/home/programs/event-scripts.nix @@ -0,0 +1,41 @@ +{ pkgs, ... }: + +{ + home.file = + let + scriptDirectory = "Library/Application Scripts/net.mousedown.EventScripts"; + fullScriptDirectoryPath = "$HOME/${scriptDirectory}"; + mosquitto_pub = "${pkgs.mosquitto}/bin/mosquitto_pub"; + in + { + "${scriptDirectory}/.hm_keyboard_connected.sh" = { + text = '' + #!/bin/sh + + if [ "$2" = "Keychron Q1" ]; then + ${mosquitto_pub} -h 10.0.0.230 -m "USB-C" -t hadata/macos/daniels_monitor -u mqtt_bridge -P verySecurePassword + fi + ''; + onChange = '' + rm -f "${fullScriptDirectoryPath}/keyboard_connected.sh" + cp "${fullScriptDirectoryPath}/.hm_keyboard_connected.sh" "${fullScriptDirectoryPath}/keyboard_connected.sh" + ''; + executable = true; + }; + + "${scriptDirectory}/.hm_keyboard_disconnected.sh" = { + text = '' + #!/bin/sh + + if [ "$2" = "Keychron Q1" ]; then + ${mosquitto_pub} -h 10.0.0.230 -m "DisplayPort" -t hadata/macos/daniels_monitor -u mqtt_bridge -P verySecurePassword + fi + ''; + onChange = '' + rm -f "${fullScriptDirectoryPath}/keyboard_disconnected.sh" + cp "${fullScriptDirectoryPath}/.hm_keyboard_disconnected.sh" "${fullScriptDirectoryPath}/keyboard_disconnected.sh" + ''; + executable = true; + }; + }; +}