Notifications
- Intro
- What you can see - the basics:
- Actions
- Identifiers and userInfo
- Running a script from a notification
- Sounds and Badges
- scriptName
- The end
#
IntroThe very first thing we need to do is create the notification like this:
Well now we have a notification but to see it you have to add
#
What you can see - the basics:The notification we made won’t actually send because apple doesn’t allow blank notifications, so lets add a title:
As well as the title you can have a subtitle and a body. Here is a diagram of them both:
They are both quite simple to understand and are used the same way as the title we made earlier.
#
ActionsAn action is a button which shows when you press and hold down on the notification. You can have up to 10.
Using our script from before we add an action like this:
There is three parameters for this. Title, URL and an optional destructive.
#
TitleTitle is a string that will be the text inside the action button.
#
UrlURL is a string that defines what link is opened when you press the button.
#
DestructiveFinally you have destructive which is a boolean value (true or false) basically it changes the button colour to red.
#
ExampleLets make one together
Now that we have a action we can check it worked by adding this
This should print
{
"title": "All the syntax",
"url": "https://scriptable.app/notification"
}
To add destructive you add another , just before the closing bracket then add true
#
Identifiers and userInfoThis section we will be covering identifier, threadIdentifier and userInfo.
#
identifierIdentifier is used to cancel or change a notification that has been scheduled but it hasn’t been received yet. Check the docs for info about it.
#
threadIdentifierAs you may have seen your notifications are automatically grouped, a set of messages from one person and a different set of messages from another person. To do this you would use threadIdentifier.
for each notification you send you can change the threadIdentifier
#
userInfoThis is used to store information in a notification. When a script is run from a notification (next section) you can do if(config.runsFromNotification) { //checks if it was ran from a notification var userinfo = Notification.opened //retrieves the value console.log(userinfo) //logs the value }
#
Running a script from a notification#
Obtaining the URLTo obtain the url that runs a script do this
This should print something like this scriptable:///run/Scriptname.
#
Opening the URLThere is three ways to open a link we will only focus on the first two for now.
notification.addAction('Run', 'scriptable:///run/scriptname')
notification.openURL = 'scriptable:///run/scriptname'
And thats it.
#
Sounds and Badges#
SoundIf you want a sound when the notification is received thankfully it's quite easy.
The sound can be one of the following:
- null (no sound)
- default
- accept
- alert
- complete
- event
- failure
- piano_error
- piano_success
- popup
#
BadgeYou may have noticed on your home screen the the top right corner of some apps there is a red circle with a number in. This is a badge, it mostly shows the notifications received from that app. However, we can change this.
#
scriptNameThis uses whats called a rich notification which lets you preview images and other things inside the notification when you hold down on it. This is not all the thing you can do with it but there is many different you can preview so I will start with 3. Note: you can’t display widgets in it and also the preview is above the title and everything else.
#
Displaying TextPerhaps the simplest thing you can do with it is display text. One of the many useful things with rich notifications is that you can do it cross script. Although here I will do it in one script for simplicity.
Now in that you may have noticed you set the quick view once the notification runs the script. This could be used for obtaining variables from different scripts.
#
Displaying a UI tableTo do this you will need to create a UI table and then just change the quick look from displaying text to
#
Displaying a websiteThis is my personal favourite because it actually allows you to interact with the website. For example, if there is a text box on the site you can type in it and also press buttons that open links (although it opens it in your default browser). To do this first get the script from displaying text above. Then make the following changes inside the if statement.
make sure to remove the other QuickLook.present too.
#
The endThats all for notifications for now! Check out everything you can do here