Skip to content

Commit

Permalink
bin/upsy-desky: add new script.
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeMcQuaid committed Dec 27, 2024
1 parent 66885fa commit 0e20b32
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions bin/upsy-desky
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
# Moves desk up or down.
set -euo pipefail

COMMAND="${1:-}"

usage() {
echo "Usage: ${0} <up|down>" >&2
exit 1
}

[ -z "$COMMAND" ] && usage

POWER_TYPE="$(pmset -g batt | grep -Eo '(Battery|AC) Power')"
[ "${POWER_TYPE}" != "AC Power" ] && exit 0

LID_UP="$(ioreg -r -k AppleClamshellState | grep AppleClamshellState | awk '{print $4}')"
[ "${LID_UP}" != "No" ] && exit 0

DESK_IP_ADDRESS="10.0.0.45"

if [ "$COMMAND" == "up" ]; then
DESK_PRESS_URL="http://${DESK_IP_ADDRESS}/button/desk_preset_1/press"
elif [ "$COMMAND" == "down" ]; then
DESK_PRESS_URL="http://${DESK_IP_ADDRESS}/button/desk_preset_2/press"
else
usage
fi

curl -X POST "${DESK_PRESS_URL}" &>/dev/null

0 comments on commit 0e20b32

Please sign in to comment.