If you have a Mac at home (like I do, it runs and is connected to my TV), you can Kodi also leverage it to control or query your home in different ways. Being an user, I thought it would be neat to be able to send and receive commands to my house using iMessages, whether I’m at home or somewhere else. iPhone Asking my Mac for a joke, it responds So to limit the scope of this article, I’m just going to implement a very simple joke bot. First of all, let’s write a shell script powered by that allows us to send messages. We need to do this, as Apple does not provide an open API. AppleScript Let’s create an actual AppleScript handler for Messages.app: This script needs to be placed in your folder. ~/Library/Application Scripts/com.apple.iChat To install the handler, open Messages.app, go to and choose the file. Preferences>General MessageReceive.script Now — upon receiving a message, Messages.app will send the message to the AppleScript receive handler. Lastly, as simply calls the shell script , we’ll have to create it as well: MessageReceive.script ~/bin/MessageReceive.sh #!/bin/bash # Set shell optionsshopt -s nocasematch sender=`echo ${1} | cut -d ':' -f 2`read line sendChuckNorrisJoke() {message=$(curl -s " " | python -mjson.tool | grep '\"joke\"' \| cut -d : -f 2 | sed 's/"/\"/g')${HOME}/bin/SendMessage.sh "${sender}" "${message}"} http://api.icndb.com/jokes/random if [[ $line =~ "joke" ]]; thensendChuckNorrisJokeexit 0fi message="I do not understand what you mean."${HOME}/bin/SendMessage.sh "${sender}" "${message}" The above script is simply a hack that only works with a Chuck Norris joke database. The concept should be clear though, i.e. you can replace this with any type of script such as your very own personal AI bot, or switching lights on/off.