Skip to content

Commit

Permalink
macos: refactor displaySwitch.sh to use m1ddc
Browse files Browse the repository at this point in the history
ddcctl doesn't work on M1 yet - kfix/ddcctl#86
  • Loading branch information
tigattack committed Dec 19, 2022
1 parent 3d6dd06 commit f8449e9
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions macOS/displaySwitch.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
#!/bin/bash
#!/bin/bash -x

query=$(echo "$1" | tr '[:upper:]' '[:lower:]')

debug=false

# https://github.com/waydabber/m1ddc
ddpath='/usr/local/bin/m1ddc'

function setInput {
/usr/local/bin/ddcctl -d "$1" -i "$2"
$ddpath display "$1" set input "$2"
}

function setBrightness {
if [ "$2" -gt "100" ]; then
printft "\nERROR: Brightness cannot be greater than 100.\n\n"
else
/usr/local/bin/ddcctl -d "$1" -b "$2"
$ddpath display "$1" set luminance "$2"
fi
}

function setContrast {
if [ "$2" -gt "100" ]; then
printft "\nERROR: Contrast cannot be greater than 100.\n\n"
else
/usr/local/bin/ddcctl -d "$1" -c "$2"
$ddpath display "$1" contrast "$2"
fi
}


numDisplays=$(/usr/local/bin/ddcctl 2>/dev/null | grep 'I:' | cut -c 10-10)
numDisplays=$($ddpath display list 2>/dev/null | wc -l | xargs echo)

if [ "$debug" = 'true' ]; then
printf '\nFound %s displays\n' "$numDisplays"
Expand All @@ -43,7 +46,7 @@ if [ "$query" = 'work' ]; then
elif [ "$query" = 'mac' ]; then

input='49' # USB-C
contrast='100'
contrast='75'

if [ "$debug" = 'true' ]; then
printf 'Determined input should be set to USB-C (%s)\n' "$input"
Expand Down Expand Up @@ -74,5 +77,5 @@ do
done

if [ "$debug" != 'true' ]; then
echo "Set input and contrast for $numDisplays displays."
echo "Set input and contrast for $numDisplays display(s)."
fi

0 comments on commit f8449e9

Please sign in to comment.