The Basics
Importing Libraries
Traditional Variables
Magic Variables
Global Variables
Strings
Declared Metadata
Property Modifier
Key Modifier
Type Casting
If & Else Statments
Repeat & Repeat Each
Functions & Macros
Menus
Variables in Jelly are mutable (meaning their value can be edited). When you create a variable, it can be used in the input of functions needing a variable. You can also set them to new values using the same syntax you use to set them in the first
place. To set a variable there are a few different options, Strings
, Numbers
,
Magic Variables
, and Global Variables
.
If you want to declare a variable with the value of a string, you can use the following syntax
var HelloWorld = "Hello World"
This will automatically be converted into the following Shortcuts actions
If you want your variable to have multiple lines of text (a newline character \n), you will want to use a multiline variable. These are declared with the following syntax
var HelloWorldLong = """
Hello World!
I have multiple lines
"""
Notice how you use triple quotes on either side of the string you want to set.
If you want to declare a variable with the value of a number, you can use the following syntax
var MeaningOfLife = 42
This will automatically be converted into the following Shortcuts actions
If you wish to convert a magic variable into a regular variable, you can set a variable to the value of a magic variable. Since magic variables are not mutable, this is how you will want to mutate the value you get in return of a function. To do this you can use the following syntax
var MyVariable = FunctionOutput
Just like magic variables, global variables are not mutable. To edit them you will need to set a variable to the global variable. This can be done with the following syntax
var MutableGlobalVar = Shortcut Input
Check out the Strings documentation to see how to place a variable into a string
If you want to assign data to a variable, after it's initialization you can use the following syntax
// Initial Value
var x = Shortcut Input
// New Value
x = "Hello World!"
// or
var x = "Hello World!"
If you want to add an item to a variable, you can use the following syntax
// Initial Value
var x = Shortcut Input
// New Value
x += "Hello World!"
// or
var x += "Hello World!"
This will turn the variable into an array, just like the shortcuts add to variable action.