_variable_parser

Type: Apple Shortcut

Platforms: iOS 16, iPadOS 16, macOS 13

Version: 1.0.0

A simple text find-and-replace parser that pairs well with Markdown editors.

Meant as an “engine,” this Shortcut is built to be used in other Shortcuts.

What it does:

  1. Takes in a text input
  2. Looks through the text input and compares it with a user-customizable list of variables in a JSON file
  3. Replaces those variables by prompting the user
  4. Outputs the result for use in another Shortcut

Getting Started

To get started, download the Shortcut above. It will ask you where you want to store your Variable file. Choose a location.

From there, you could run the Shortcut. It will ask you for a text input and then show you the output.
However, its most powerful when you build it into a workflow.

Examples

For example, I have a Create New Bear Note Shortcut that uses my other Shortcut, _template_picker, to take in a Markdown template, replace all the variables, and stick it in Bear.

_variable_parser will take care of asking me what to name my note, what date to stick in it, and everything else.

Included variables

On first run, the Shortcut will place a file named custom_variables.json in the folder you specified. By default, this file contains these variables:

{{title}}

{{zoom_url}}

{{author}}

{{location}}

{{date}}

{{today}}

{{tomorrow}}

{{yesterday}}

Want to add your own? Open the JSON file and read the documentation below:

custom_variables.json Documentation

Each item in the JSON file can have these attributes:

"{{date}}": {
	"prompt": "Enter a date:",
	"default_value": "today",
	"prefix": "This date you entered, ",
	"suffix": ", is a good date.",
	"action": "date",
	"date_format": "yyyy-MM-dd"
}

The structure is designed so that you add on functionality as you see fit. For example, you can simply have a prompt value, or just a prefix value. Any number of the below can be added or subtracted.

"{{date}}"

Accepts: object

This value, within quotes, is what the Shortcut looks to replace. If it finds this value in the document that was inputted into the Shortcut, it will replace every instance of this string.

This is case sensitive.

"prompt"

Accepts: string

This will cause an “Ask for Input” modal to appear on screen, and the value for the key will be used as the title.

The text value that the user inserts will be used as the value the {{date}} gets replaced with.

The user can insert multiple lines of text.

"default_value"

Accepts: string

When a prompt is provided, this will fill the prompt with the value of this key.

If a prompt is not provided, this value will be used by default.

"prefix"

Accepts: string

When provided, this will prefix and prepend the value entered in the prompt or the default_value.

"suffix"

Accepts: string

When provided, this will suffix and append the value entered in the prompt or the default_value.

"action"

Accepts: string parameter

This takes an argument. More arguments might be added in the future.

List of acceptable arguments:

  • date

date argument

This argument will take the prompt or default_value input and run it through a Date shortcut action. Any appropriate Specified Date input can be used.

This argument allows one other JSON key to be added under the {{date}} object: date_format. You can use any Unicode Date Markup value here:

{
	"action": "date",
	"date_format": "yyyy-MM-dd"
}

Examples

Perform basic search/replace operations:

"time": {
	"default_value": "money"
}

Format a Zoom URL using markdown:

"{{zoom_url}}": {
	"prefix": "[Zoom URL](", "suffix": ")",
	"prompt": "What's the Zoom URL?"
}

Format dates for use as Bear tags:

"{{date}}": {
	"action": "date",
	"prompt": "Enter a date:",
	"default_value": "today",
	"date_format": "yyyy/MM/dd",
	"prefix": "#date/"
}

Release Notes

v1.0.0
  • First release
  • Creates template on first run
  • Has support for “date” actions
  • Supports prefix and suffix keys