Working with Functions and Macros
How to create a function using Jellycuts

I was inspired to write this blog post after reading a thought-provoking point on Reddit:
"During all of those years, there has been one key feature [within Shortcuts] that I found missing and thought would come soon: Function. What's that? It's useless? You can already do it? Well, I disagree. I wish for it regularly, as well aselif
and[and/or]
inif
blocks (which is finally coming)." — 0zzySheIIey on Reddit
The beauty of this complaint is that it’s already addressed—thanks to Jelly Language and the Jellycuts IDE.
Jelly Language is a powerful tool designed for developers looking to create more sophisticated shortcuts, beyond what’s typically available.
Jellycuts is a mobile-first IDE that empowers you to write these advanced shortcuts using code.
Take the example below: we’re creating a macro that triggers a countdown timer. With each passing second, a notification displays the remaining time—all achieved in under 20 lines of code (excluding comments).
We'll delve into why we call it a Macro instead of a function in an upcoming post. For now, enjoy exploring this newly added feature that simplifies writing functions within Apple Shortcuts.
import Shortcuts
#Color: red, #Icon: clock
macro countdown(count){
// Print out a Countdown Using Notifications
macro printMsg(idx, msg){
// Subtract total secs - current
math(input: count, operation: -, operand: idx) >> remaining
// Create notification message
var message = "${remaining} seconds"
// Publish notification
sendNotification(body: message, title: "Countdown", sound: false)
}
// Create a Loop
repeat(count) {
// Update countdown timer
// RepeatIndex = Auto Index
printMsg(RepeatIndex)
// Wait
wait(seconds: 1)
}
}
// Start function
countdown(10)
Write a Function using Jellycuts