Created
January 30, 2017 16:20
-
-
Save doctorfree/f75cd0d26dfc95dadf894e63a08f9e99 to your computer and use it in GitHub Desktop.
Send IFTTT phone channel a tagged SMS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# ifttt - Send a text message to my IFTTT phone channel with a tag that | |
# triggers a corresponding Harmony activity. | |
# | |
# My IFTTT Phone Channel number | |
# (Replace ########## with your IFTTT phone number) | |
IFT="##########" | |
MSG= | |
usage() { | |
printf "\nUsage: ifttt [lights | appletv | bluray | tv | off] [on | off]" | |
printf "\n\tFirst argument required. Second argument optional, default on" | |
printf "\n\nExample invocations:" | |
printf "\n\tTurn all lights on" | |
printf "\n\t\tifttt lights on -or- ifttt lights" | |
printf "\n\tTurn all lights off" | |
printf "\n\t\tifttt lights off" | |
printf "\n\tTurn Apple TV on" | |
printf "\n\t\tifttt appletv on -or- ifttt appletv" | |
printf "\n\tTurn Apple TV off" | |
printf "\n\t\tifttt appletv off" | |
printf "\n\tTurn Blu-Ray player on" | |
printf "\n\t\tifttt bluray on -or- ifttt bluray" | |
printf "\n\tTurn Blu-Ray player off" | |
printf "\n\t\tifttt bluray off" | |
printf "\n\tTurn TV on" | |
printf "\n\t\tifttt tv on -or- ifttt tv" | |
printf "\n\tTurn TV off" | |
printf "\n\t\tifttt tv off\n" | |
exit 1 | |
} | |
[ "$1" ] || usage | |
[ "$1" = "-u" ] && usage | |
inst=`type -p osascript` | |
[ "$inst" ] || { | |
echo "AppleScript is not supported on this platform." | |
echo "Unable to send text message via command line." | |
usage | |
} | |
# Convert arguments to lower case | |
activity=`echo "$1" | tr '[:upper:]' '[:lower:]'` | |
action=`echo "$2" | tr '[:upper:]' '[:lower:]'` | |
[ "$activity" = "lights" ] && { | |
[ "$action" = "on" ] && MSG="#LightsOn" | |
[ "$action" = "off" ] && MSG="#LightsOff" | |
[ "$action" = "spin" ] && MSG="#Spin" | |
[ "$action" ] || MSG="#LightsOn" | |
} | |
[ "$activity" = "appletv" ] && { | |
[ "$action" = "on" ] && MSG="#AppleTV" | |
[ "$action" = "off" ] && MSG="#AppleOff" | |
[ "$action" ] || MSG="#AppleTV" | |
} | |
[ "$activity" = "bluray" ] && { | |
[ "$action" = "on" ] && MSG="#Bluray" | |
[ "$action" = "off" ] && MSG="#BlurayOff" | |
[ "$action" ] || MSG="#Bluray" | |
} | |
[ "$activity" = "tv" ] && { | |
[ "$action" = "on" ] && MSG="#WatchTV" | |
[ "$action" = "off" ] && MSG="#Off" | |
[ "$action" ] || MSG="#WatchTV" | |
} | |
[ "$activity" = "off" ] && { | |
MSG="#Goodnight" | |
} | |
[ "$MSG" ] || usage | |
osascript << EOT | |
tell application "Messages" | |
send "$MSG" to buddy "$IFT" of service "SMS" | |
end tell | |
EOT | |
[ "$activity" = "off" ] && { | |
sleep 5 | |
MSG="#Bedtime" | |
osascript << EOT | |
tell application "Messages" | |
send "$MSG" to buddy "$IFT" of service "SMS" | |
end tell | |
EOT | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment