Let's Create A Simple Alert
The easiest way to learn how to use Scriptable is by creating a simple alert.
#
We will make an alert where we will ask for your birth year and returns us another alert with your age!Create a new Script in Scriptable. To define an Alert we put it in a variable "alert".
When running your script it should show you this:
Did it work? Nice! if not? You can ask your problem in Discord or Reddit. Now we will add a textfield to the alert. We can do that by using addTextField(placeholder, value). Let's change the button because Cancel looks a bit boring =D. You can add buttons (also called actions) by using addAction(title)
To retrieve the year you have to use .then() after you've presented the alert. .then() is used when there is a promise. Index is the number of the textfield. (Always starts at 0!)
When running your script it should show you this:
Now we will calculate your age and show it again with an Alert. To calculate your age we will use Date to get the current year instead of putting it in a variable. Because year is text it will be hard to calculate your age so we will change it to a Number with parseInt(). Create a new Alert and give it a nice title and present it.
When running your script it should show you this:
You did it! Next we will learn how to create a notification!