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; + }; + }; +}