Your first script
A MaSH script is called a mashlet. This chapter shows you where to write one and what it does when it runs.
Where you write it
Section titled “Where you write it”- Open Settings > MaSH. The Scripts tab lists the scripts you can see.
- Choose Add new. This opens the editor, Mashup, in a new tab.
- Click the name at the top and give your script a name. Names don’t have to be unique, but a clear one helps you later.
The editor has two modes. Visual mode shows a script as cards you can drag. Code mode shows the text. This tutorial is all text, so switch to Code mode if you see cards.
Type a script into the editor, then choose Run. Whatever the script prints appears in the Output panel. Choose Save to keep it.
The other tabs in Settings > MaSH (Events, Schedule, Webhooks and Logs) are where a saved script gets attached to something that runs it automatically. Reacting to events covers that.
Here’s the smallest useful script:
printline "Hello from MaSH"Hello from MaSHprintline("Hello from MaSH")Hello from MaSHprintline writes a line of text to the output. print does the same without ending the line:
print "Hello, "print "world"printlineprintline "A new line"Hello, worldA new lineprint("Hello, ")print("world")printline()printline("A new line")Hello, worldA new lineText goes in double quotes. A line that starts with # is a comment. MaSH ignores it. Use comments to explain why the script does something.
# This line is ignoredprintline "This one runs"This one runs# This line is ignoredprintline("This one runs")This one runsTwo ways to write the same thing
Section titled “Two ways to write the same thing”MaSH reads like English if you want it to. It also accepts the curly-brace style most programming languages use. Both of these work:
set greeting to "Good morning"printline greetingGood morninggreeting = "Good morning"printline(greeting)Good morningset greeting to "Good morning"printline(greeting)greeting = "Good morning"printline(greeting)Good morningset greeting to "Good morning" is the natural form. greeting = "Good morning" is the standard form. You can mix them in one script, but pick one and stick to it so other people can read your work. The tutorial mostly uses the natural form for set, and parentheses when calling methods.
Putting a variable in text
Section titled “Putting a variable in text”A variable is a name that holds a value. You can drop a variable into text by putting its name inside double curly braces:
set name to "Grace"printline "Hello, {{name}}"Hello, Gracename = "Grace"printline("Hello, {{name}}")Hello, GraceThis is called interpolation. You can put a sum inside the braces too:
printline "Two plus two is {{2 + 2}}"Two plus two is 4printline("Two plus two is {{2 + 2}}")Two plus two is 4Try it
Section titled “Try it”Change the script so it says hello to you by name, and then prints a second line saying how many letters are in your name. (Working with text in Values and arithmetic shows how to count letters.)
In the next chapter you’ll meet the kinds of value MaSH works with.