Created
January 30, 2017 16:36
-
-
Save doctorfree/42c5cc4bcce7c7c402449b94a08cd558 to your computer and use it in GitHub Desktop.
Send IFTTT phone channel an 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