Notifications via Pushover Service & Keyboard Maestro

Hello All,,

I'm trying to use this action and I keep getting this error:

{"token":"invalid","errors":["application token is invalid"],"status":0,"request":"4505c4b0-70d2-4fee-a26a-2a0de5620e15"}

I created a new API and registered the device again just in case but still getting this message. Any clue?

Thanks

I think I figured it out the previous error, but now I'm getting this another message:

The output of plug in action "Pushover Notification" is:

~/Library/Application Support/Keyboard Maestro/Keyboard Maestro Actions/Pushover Notifications/PushoverNotification.scpt: execution error: The command exited with a non-zero status. (26)

I'm using the 2019 version

thanks!

Hi @ivomarkovic, you can use the macro and download the plugin from this post:

Could you post a screenshot of your macro?
What do you mean by "2019 version"?

Thanks for your answer! @appleianer

Here is the screenshot of the action and the error message:

The github version date downloaded and installed

By the way, I'm using Keyboard Maestro 8.2.4 version

And this is the way my .scpt looks like after I changed the keys (I tried to put the keys between quotes and without and I'm having the same error result):

-- PO_UserKey is the User Key listed on the page after you login, can also be a group key

set PO_UserKey to ufpaqjvcbvphg7ufix2uf883gnwips

-- PO_Token is the application token from the appliation created on the Pushover site

set PO_Token to ak2wucr9gqdbihhasff2o3wxfejf9v

-- PO_APIURL is the url to post the notification too

set PO_APIURL to "https://api.pushover.net/1/messages.json"

-- fetch settings from Keyboard Maestro

tell application "Keyboard Maestro Engine"

-- look up action parameters in Keyboard Maestro

set Priority to system attribute "KMPARAM_Priority"

set Title to system attribute "KMPARAM_Title"

set UrlStr to system attribute "KMPARAM_URL"

set UrlTitle to system attribute "KMPARAM_URL_Title"

set Message to system attribute "KMPARAM_Notification_Message"

set AlertSound to system attribute "KMPARAM_Notification_Sound"

set FileAttachment to system attribute "KMPARAM_File_Attachment"

end tell

if ((length of UrlTitle ≥ 14) and ((text 1 thru 14 of UrlTitle) is "Optional title")) then

set UrlTitle to ""

end if

if ((length of UrlStr ≥ 12) and ((text 1 thru 12 of UrlStr) is "Optional URL")) then

set UrlStr to ""

end if

if ((length of FileAttachment ≥ 13) and ((text 1 thru 13 of FileAttachment) is "Optional file")) then

set FileAttachment to ""

end if

-- turn notification nice names to api names ("Piano Bar" -> "pianobar")

set AlertSound to do shell script "echo " & quoted form of (AlertSound) & " | tr A-Z a-z"

set AlertSound to remove_spaces(AlertSound)

if AlertSound is "pushoverecho" then

set AlertSound to "echo"

else if AlertSound is "alienalarm" then

set AlertSound to "alien"

end if

-- Use in debugging, can run without KM

--set Priority to "Normal"

--set Title to "Test Title"

--set Message to "Test Message"

--set AlertSound to "User Default"

if Priority is "Normal" then

set PO_Priority to 0

else if Priority is "High" then

set PO_Priority to 1

else if Priority is "Low" then

set PO_Priority to -1

else

set PO_Priority to -2

end if

-- build curl command line

set curl to "curl -s "

set curl to curl & "--form-string "token=" & PO_Token & "" "

set curl to curl & "--form-string "user=" & PO_UserKey & "" "

set curl to curl & "--form-string "title=" & Title & "" "

set curl to curl & "--form-string "html=1" "

set curl to curl & "--form-string "message=" & Message & "" "

set curl to curl & "--form-string "priority=" & PO_Priority & "" "

set curl to curl & "--form-string "sound=" & AlertSound & "" "

if length of UrlStr > 0 then

set curl to curl & "--form-string "url=" & UrlStr & "" "

set curl to curl & "--form-string "url_title=" & UrlTitle & "" "

end if

if length of FileAttachment > 0 then

set curl to curl & "-F "attachment=@" & FileAttachment & "" "

end if

set curl to curl & PO_APIURL

-- make it so

do shell script curl

-- subroutine to remove spaces

on remove_spaces(the_string)

set AppleScript's text item delimiters to space

set the item_list to every text item of the_string

set AppleScript's text item delimiters to ""

set the_string to the item_list as string

return the_string

end remove_spaces

@ivomarkovic please delete the script, because it contains the Pushover User Key and it should not fall into foreign hands!!!!!

@ivomarkovic I am currently using KM 9.2, but the Pushover plugin worked fine for me even under version 8.xx.

You used your pushover key and also the token without the quotes "xxxxxxxx". That should be the error.

Please correct it as in my screenshot and then try again and please create a new Pushover User Key.

Thanks, I have already regenerate them

Thanks again, but as I said in I tried with and without quotes and the error is the same

@ivomarkovic but now it gets complicated :wink:

This is what it looks like in my Pushover account:

You also have macOS and iOS enabled?

In the macOS Accessibility you have also enabled AppleScript and System Events:

Please enter your Pushover Key and App Token in the following macro and try if it works:

05)Pushover Script Forum <6FE6 210530T114507>.kmmacros (20,4 KB)

Yes, I have both devices enabled (actually the status is Trial period)

This is weird, I don't see them listed there. I just see Keyboard Maestro Engine.app and Keyboard Maestro.app. This could be due to that I'm using version 8?

This didn't seem to be working. From the log file I got this:
2021-05-30 22:31:28 Invalid Plug In Action with Name Pushover-Notifications-master

Thanks for trying to help once again! I really appreciate it!

Original author here, I've completely neglected this plug-in (it's been working for me so I hadn't really peeked in for a few years), anyway I've pushed a big update to bring it up to speed with the latest API. I now support file attachments and the new custom sounds.

GitHub repository is at: https://github.com/kvanh/Keyboard-Maestro-Pushover-Notifications

Thanks to @trych for getting the file attachment stuff going while I was being negligent. I used his stuff as the basis of my update but I do a bit of error checking on the file attachment before sending. I also restrict the attachments to files with an jpg, jpeg, png or gif extensions and verify it's under the API limit on file sizes.

Change Log:

  • Changed URL entry to Keyboard Maestro "TokenString" so it appears in UI as a single line instead of multi-line text.
  • Added support for Pushover custom sounds. Upload a custom sound to Pushover, then use it here.
  • Fixed issue if optional entries were shorter than the default value returned from Keyboard Maestro
    • Applescript will error out on "text 1 thru 14 of stringValue" if stringValue is shorter than 14 characters
    • fix by using "text 1 thru end of stringValue"
  • Added new(ish) sound selection "Vibrate"
  • Fixed issue where sound selection wouldn't work if not in lower case and no spaces
    • Also "Pushover Echo" is just "echo" in the API and "Alien Alarm" is just "alien"
    • thanks to trych for fixing this years ago on their GitHub
  • Added support for image attachments
    • Image attachment paths can use unix style "~/" as a shortcut for the home folder
    • Extended trych's code by adding limits on attaching files:
      • Make sure the file exists and is passed on the command line in an appropriate quoted fashion
      • Pushover specifically only allows image attachments so this restricts to files with extensions jpg, jpeg, png, and gif.
      • Max file size allowed is (as of 2021-05-30) 2,621,440 bytes
    • NOTE: Because this code actually examines the file size and file extension of the file you may trigger macOS privacy protections
      and be asked to approve access to the file location. If you don't attach files, this security notice won't trigger.
2 Likes

I'm using Keyboard Maestro 9 on the latest Big Sur I don't have System Events in my Accessibility settings (I do have Keyboard Maestro and Keyboard Maestro Engine).

However under Automation, Keyboard Maestro and Keyboard Maestro Engine both are set to be able to control System Events.

image

Try opening the PushoverNotification.scpt file in Script Editor. Scroll to the very bottom of the script and add a line:
return curl

this will make the script return the command line it's using to KM. Set the Pushover Notification action to Display results in a window. Copy that, replace the user/api tokens with xxx (don't change any quote marks) and post here.

Crud, forgot to put in my Change Log that I found a bug in the code where messages/titles/etc... with double quotes or backticks in them would not send properly to Pushover. I fixed it by replacing those characters with the HTML entity version.

Scrolling back through the thread I noticed that emoji and international characters weren't working. I've fixed this as well. Per the wiki, I changed the plug-in from retrieving variables using System Attribute to:

set as_My_Var to do shell script "echo $KMPARAM_My_Var"

Fixed it right up.

For some reason, this last update works fine in my system!

Thanks for all your help @kvanh and @appleianer

Very Appreciated!

1 Like

I'm glad @ivomarkovic that it works for you now :+1:
Have fun with the pushover notifications then.

Thanks in advance for your great work @kvanh :+1:

Your plugin is used by me every day dozens of times. However, with your upgrade I get a problem in displaying the text.

The first one (Purple) is about the new plugin. Here the first line of text is no longer displayed separately. The text is formatted in one line.

The second (Green) is the old plugin, where the first line is displayed separately in the notification.
The date and time is then in the second line.

Unfortunately, I do not know so well with scripts. Can you help me with the formatting, so that I get the notification (formatted) as in the old plugin displayed?

macOS Catalina & Big Sur
Keyboard Maestro 9.2

I'm seeing this too. I suspect it has to do with getting the contents with the do shell script "echo...". Looking into it.

1 Like

I just pushed an update to GitHub that should resolve this. I was right the echo command was the cause. I switched to using printenv. I'll submit a note for the wiki to get updated.

1 Like

It works fine now with formatting @kvanh :+1:
Thank you so much for reviewing the plugin so quickly.