Shortcuty Studio
Shortcuty Studio

Documentation

Learn Shortcuty Script, from your first shortcut to the full language syntax.

Types and optional values

Use these type names in annotations and conversions:

FamilyTypes
GeneralValue, Any, NoOutput
ScalarsText, Number, Boolean, Date, URL, Location
CollectionsList, List<T>, Dictionary
ContentPhotoMedia, Media, Image, File, PDF, RichText, Contact
NativeNative<content-class>
CompositionOptional<T>, A | B

Types flow through action outputs, literal and alias assignments, lists, known dictionary fields, property access, branches, menus, loops, optional storage, and explicit casts. A branch that can return different known types has a union type. Absence produces an optional type instead of erasing the known content type.

Typed storage and optional values

Use the generic storage spelling to declare a persistent value's type:

shortcut:
  parking = location.current()
  storage.set<Location>("ParkingPinLocation", parking)
  if let saved = storage.get<Location>("ParkingPinLocation"):
    maps.directions(mode: "Driving", destination: saved)

storage.get<T> returns Optional<T>. if let name = expression: evaluates the expression once, assigns its result to a named variable, and checks whether it has a value. Expressions can be storage reads, existing variables, dictionary lookups, properties, action or function results, literals, or arithmetic. Calls and their arguments evaluate in source order before either branch runs. Rebinding a name reads its previous value on the right-hand side before replacing it.

shortcut:
  record = {"count": 0}
  if let count = record["count"]:
    next = count + 1
    show("Next count: \(next)")
  else:
    show("No count available")

The successful branch sees the binding as present. Its declared content type is retained; checking an unknown dictionary field cannot establish that it is a Number. The binding is also visible in else and after the condition, where normal continuing-path analysis retains any possible absence. Guarding a copied binding does not unwrap its original source. if let uses Apple's Has Any Value condition, not Boolean truthiness or a text-length comparison; zero and false are values. Empty text and collections follow that native presence condition rather than a language-level nonempty test. Use is not empty when an explicit emptiness check is intended.

storage.set<T> rejects an unchecked optional and rejects a value incompatible with T. Reusing the same literal key with conflicting declared types is an error. Optional binding does not bypass invalid references, casts, or arithmetic operand checks in the right-hand expression.

An unused storage retrieval is a warning. Missing outputs, invalid enum literals, conflicting storage types, incompatible calls, and unsafe optional use are errors in authored source.

Connection results

Every connection with sufficient action metadata is classified separately:

ResultMeaningWhat to do
DirectThe value matches the input.Pass it directly.
ConversionShortcuts can try to convert the value.Test it on your device; Studio won’t add a conversion for you.
IncompatibleThe value does not match the input.Use a compatible value or a supported conversion.
UnknownStudio can’t tell whether the value fits.Check the action’s input and test your data.

Imported source is checked when rebuilt. The importer may preserve individual original connections it can verify but cannot represent safely as newly authored source. Review the resulting diagnostics; new or changed connections still need supported authoring and normal checks.

Explicit content conversion

as_type(value, "Type") applies Apple's variable-editor content coercion without adding an action. The value must be a variable reference, and the target must be one of PhotoMedia, Media, Image, Text, Number, Dictionary, Date, File, URL, Location, or Contact. Casts receive the same source-reference, optional, and compatibility checks as direct action parameters. Property and dictionary access may follow the call, such as as_type(file, "File").name.

For a video selected from Photos, explicitly convert to Media before making the GIF:

shortcut:
  video = photos.select(multiple: false, media_type: "Videos")
  gif = images.make_gif(input: as_type(video, "Media"), auto_size: true, loop: true)
  photos.save(item: gif)

This conversion saved a GIF in a device test; connecting Photos directly did not. Test other conversions separately.

Travel-time numbers and output properties

maps.travel_time returns trip information. Use as_type(trip.travel_time, "Number") for numeric work, not a whole-trip cast, localized-text parsing, or dictionary lookup.

shortcut:
  first = maps.travel_time(destination: "San Francisco City Hall", get_directions_action_mode: "Driving")
  first_cost = as_type(first.travel_time, "Number")
  second = maps.travel_time(destination: "Ferry Building, San Francisco", get_directions_action_mode: "Driving")
  second_cost = as_type(second.travel_time, "Number")
  result(first_cost < second_cost)

This example compares two destinations. To plan a round trip, include the return leg. Time estimates alone do not find the best order for several stops.

Apple declares Travel Time as WFTimeInterval with Number conversion. This does not establish the numeric unit or device behavior. Compare consistent durations; do not label seconds/minutes without evidence. Maps failures, permissions, and optimizer quality need runtime tests.

Use output_properties in the action reference to find dot-access names, types, and supported conversions. A property is a value, not an action. Check that you have one value rather than a list, and handle missing values separately.

Shared action contracts

See the Action reference for accepted values and return types. The same information is available as JSON or from python3 -m shortcutscript schema web.request.

web.request accepts one body alternative (json, form, or body), and an explicit body_type must agree with it. show_headers accepts literal true or false; unsupported values are diagnosed rather than ignored. Native HTTP methods retain variable references. Inactive imported native body fields are preserved with inactive_json:, inactive_form:, or inactive_file:; empty inactive bodies are omitted.

files.filter accepts either an explicit definition or ordinary filter arguments. The ordinary form requires sort_by and order; property and equals must appear together. limit_enabled belongs to the explicit-definition form. A numeric limit reference is preserved instead of silently becoming 1. shortcuts.run takes its target positionally. Shortcuty adapters reject arguments that their operation would otherwise ignore.

Use a documented choice. If the available choices are unknown, confirm them in Apple Shortcuts.

Base64 Encode returns Text. Decode can yield files or text; do not assume you have an Image without checking the result.

Dictionary lookup types

A fixed key such as record["count"] retains its known field type. A key stored in a variable can do the same when its text is known before the shortcut runs. A key chosen at runtime can select any field, so its result includes the known possible field types and possible absence. Unknown dictionary contents remain unknown. if let removes possible absence in its successful branch, but does not turn a Number | Text result or an unknown value into a Number. Use a supported conversion or a more specific data contract before numeric work. See Calling actions for the lookup syntax and missing-value recipe.

shortcut:
  record = {"count": 4, "name": "Photo"}
  key_name = "count"
  total = value(record, key: key_name) + 1
  result(total)