I want to write an AppleScript that
- runs (in a loop) until I press esc
- "listens" for keystrokes 1, 2, etc.
- executes a given command for a each keypress (running a shell command
ddcctlto change secondary monitor brightness/contrast)
I've searched and everything I find relates to simulating a key press.
(If this can be done in
bash that's fine but I don't know enough shell scripting to even start...)
Based on this tip, I wrote the shell script below, which works great, but only if I run it within Terminal. Is there any way to run this script 'invisibly', say, from Spotlight or via AppleScript
do shell script, and have it respond until I exit?
#!/bin/bash if [ -t 0 ]; then stty -echo -icanon -icrnl time 0 min 0; fi keypress='' while [ "$k" != "^[" ]; do case "$k" in 1) ddcctl -d 1 -b 10;; 2) ddcctl -d 1 -b 20;; 3) ddcctl -d 1 -b 30;; # ...etc... 0) ddcctl -d 1 -b 100;; esac k="`cat -v`" done if [ -t 0 ]; then stty sane; fi exit 0