Skip to content

Instantly share code, notes, and snippets.

@c99koder
Last active December 7, 2017 21:25
Show Gist options
  • Save c99koder/6773332 to your computer and use it in GitHub Desktop.
Save c99koder/6773332 to your computer and use it in GitHub Desktop.
Forward iMessges to Pebble using PushOver. Fill in your APP_TOKEN and USER_KEY. In the "Alerts" tab of Messages' settings, tell it to run this script for "Message Received" and "Text Invitation"
on push(title, message)
set APP_TOKEN to "..."
set USER_KEY to "..."
do shell script "curl -s -F token=" & APP_TOKEN & " -F user=" & USER_KEY & " -F title=\"" & title & "\" -F message=\"" & message & "\" https://api.pushover.net/1/messages.json"
return
end push
using terms from application "Messages"
on message received theMessage from theBuddy for theChat
my push((full name of theBuddy), theMessage)
end message received
on chat room message received theMessage from theBuddy for theChat
my push((full name of theBuddy), theMessage)
end chat room message received
on active chat message received theMessage
#uncomment to push the active chat to Pebble
#my push((full name of theBuddy), theMessage)
end active chat message received
on addressed chat room message received theMessage from theBuddy for theChat
my push((full name of theBuddy), theMessage)
end addressed chat room message received
on addressed message received theMessage from theBuddy for theChat
my push((full name of theBuddy), theMessage)
end addressed message received
# The following are unused but need to be defined to avoid an error
on message sent theMessage for theChat
end message sent
on received text invitation theText from theBuddy for theChat
end received text invitation
on received audio invitation theText from theBuddy for theChat
end received audio invitation
on received video invitation theText from theBuddy for theChat
end received video invitation
on received remote screen sharing invitation from theBuddy for theChat
end received remote screen sharing invitation
on received local screen sharing invitation from theBuddy for theChat
end received local screen sharing invitation
on received file transfer invitation theFileTransfer
end received file transfer invitation
on buddy authorization requested theRequest
end buddy authorization requested
on av chat started
end av chat started
on av chat ended
end av chat ended
on login finished for theService
end login finished
on logout finished for theService
end logout finished
on buddy became available theBuddy
end buddy became available
on buddy became unavailable theBuddy
end buddy became unavailable
on completed file transfer
end completed file transfer
end using terms from
@n8henrie
Copy link

Thanks for the work on this script! I recommend you change your curl script portion to use quoted form of instead of escaping double quotes to avoid issues with special characters. Here's an example that uses each:

property app_auth : "your app auth here"
property user_auth : "your user auth here"


set complex_message to "this is & a complex '  & ( ( )\" message * that made it through."
set simple_message to "Looks like it choked on the complex message."

on old_way(message)
    set title to "this uses escaped double quotes"
    do shell script "curl -s -F token=" & app_auth & " -F user=" & user_auth & " -F title=\"" & title & "\" -F message=\"" & message & "\" https://api.pushover.net/1/messages.json"
end old_way

on new_way(message)
    set title to "this uses 'quoted form of'"
    do shell script "curl -s -F token=" & app_auth & " -F user=" & user_auth & " -F title=" & quoted form of title & " -F message=" & quoted form of message & " https://api.pushover.net/1/messages.json"
end new_way

try
    old_way(complex_message)
on error
    old_way(simple_message)
end try

try
    new_way(complex_message)
on error
    new_way(simple_message)
end try

Result:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment