Reddit - Unread mail count

I've made a widget for unread reddit messages.
Set the predefined action to open URL:
and on long press to open URL: if you want an option to go to your front page too

-- You need to go to while signed in, copy the link from the JSON button next to Unread Messages and paste it into the script below.

set jsonurl to "YOUR URL"
tell application "JSON Helper"
    set UnreadFull to fetch JSON from jsonurl
    set unreadcount to dist of |data| of UnreadFull
end tell

if unreadcount is 0 then
    set unreadcount to " "
end if
return unreadcount

It doesn't work for me. When I try to compile the script, BTT gives me an error in JSON in the line
set UnreadFull to fetch JSON from jsonurl
The error given is: "Expected end of line but found identifier."

Note to everyone here

To get this to work you will need to install JSON helper.

Note to @Doa:
You might want to put that in your post!

1 Like

Thank you. Would it be possible to do the same with the notifications of this forum?

Total mac newbie here (Though 25 years SA and DevOps on Unix and Linux systems). I created the script, saved it with scpt suffix, opened BTT config, selected touchbar, added touchbar button, and set it to launch the script. how do I get it to set the button title text to the variable "unreadcount", or what to do on long press, etc? Are these even BTT questions or should I educate myself a bit more about mac tools on the whole?

You can also have the script just entered into BTT, instead of having to save as a script, but use which ever is best for you. Assuming the script result is just the unreadcount, it will show automatically next to the icon you've put in. Otherwise it will return whatever text result your script gives. Just make sure "show only icon, no text" isn't ticked under Common.
Long Press is under Common menu for the widget. Scroll to the bottom and you'll see it. Type in whatever word or phrase you want to use for the named trigger,
Then go to Named & Other Triggers (cmd+9), and create a Named Trigger. (Select Trigger > General> Named. Type in the exact phrase/word you entered under long press. Then you just create whatever action you want to happen when you long press the widget.

Gotcha! could manage to trigger the named trigger bit, but I'll read through it. looks nice enough :slight_smile:
The scripts I keep in a directory with snippets I like to keep in git, so I'll leave it outside BTT for now (I'll see which way makes it easier to backup and restore)
While playing around I made the laptop lock when my Pebble watch moves away, but couldn't do the same for my phone for some reason (it doesn't register as BLE, oddly enough). This is nice. It'll be fun to dig into this over the weekend, thanks @Doa!