Using Dynamic Placeholders

Alfred offers dynamic snippets, which allow you to insert dynamic content into a snippet when using Clipboard Snippets and in certain workflow objects.

The workflow objects where dynamic content can be used are the Copy to Clipboard, Large Type and Write Text File outputs.

What is Dynamic Content?

When creating a snippet, or setting the output of a workflow, you'll most likely include some fixed, pre-defined text.

In other instances, you may want to add the current time, the date in a week, or the contents of your clipboard; This is dynamic content, as it can change every time the snippet is pasted.

In this example, various keywords in curly brackets are used to paste dynamic content amongst the pre-defined snippet text.

Example of a text snippet with dynamic content

You can add the following types of data dynamically:

Using Dynamic Content

Date and Time

To use a dynamic date or time, begin with date, time, or datetime. You can follow this with optional date arithmetic to calculate a date/time in the future or past, and optional default formats (short, medium, long, full). When no format is specified, Alfred uses the "medium" format as default.

For example, {date} will paste the current date in default format, while {date +7d +3h:long} will give me the date in seven days, three hours, in the long format.

The {date}, {time} and {datetime} placeholders use your macOS default formats. You can change these in your Mac's System Preferences > Language & Region > Advanced settings under Date and Time.

Setting your Date and Time preferences

Example date and time formats


Date Arithmetic

Need to set a date or time at a future or past date? The following formatting allows you to add date and time processing.

Date arithmetic +/-

1Y : Year
1M : Month (strict uppercase)
1D : Day
1h : Hour
1m : Minute (strict lowercase)
1s : Second

Add the date formatting after the date, time or datetime placeholder, for example, to show tomorrow's date, use:

{date +1D}

Or to show the time 3 hours and 20 minutes ago, use:

{time -3h -20m}

Date arithmetic works in combination with date formatting, allowing full control over the date and time placeholders.

Date examples, including arithmetic

  • Time 10 minutes and 30 seconds ago in long format: {time -10m -30s:long}
  • Date and time 2 years and two months ago in full format: {datetime -2Y +2M:full}
  • Date and time 1 year ago, showing the date in two digit format: {datetime -1Y:yy}

Advanced Date Formatting using Unicode formats

Alternatively, you can use the Unicode formats for dates to be more specific with your date formatting. These can also be used with arithmetic included before the colon symbol.

Unicode Date Format Patterns (Advanced)

  • ISO 8601 date format: {date:yyyy-MM-dd'T'HH:mm:ssZZZZZ}
  • Day/Month/Year 7 days ago: {date -7d:dd/MM/yy}
  • 12-hr clock with time zone: {date:K:mm a, z}

Cursor Placement

Use {cursor} to position the cursor somewhere other than the end of the pasted text.

Note that there are limitations to the cursor placement; Certain apps may not allow you to re-position the cursor beyond the beginning of the current line.

Clipboard contents

Use {clipboard} by itself to paste the content of your latest clipboard entry as plain text. You can also specify which clipboard item to use by using the clipboard offset, and perform some basic formatting (uppercase, lowercase and capitals).

Dynamic Placeholder content example

Formatting the clipboard contents before pasting

The Clipboard placeholders allow you to quickly format the text as follows:

  • {clipboard}
  • {clipboard:uppercase}
  • {clipboard:lowercase}
  • {clipboard:capitals}

Using clipboard offset to paste previous clipboard items

The clipboard offset allows you to specify which clipboard items you want Alfred to paste.

{clipboard} and {clipboard:0} represent the latest item in your clipboard; these may differ if your workflow manipulates the clipboard content.

For the next items in the clipboard list, use {clipboard:1}, {clipboard:2}, and so on.

Note: Clipboard History must be enabled on your Mac in order for {clipboard:x} items to be available.

An example of clipboard offset usage

For example, if you copy these three text items to your clipboard:

First item copied: Andrew
Second: hedgehogs

And then create a snippet or workflow output as follows:

Hi {clipboard:2}, thanks for your question about {clipboard:1}. You can find your answer here: {clipboard:0}.

Resulting in:

Hi Andrew, thanks for your question about hedgehogs. You can find your answer here:

Order of operations for clipboard placeholders

Given that there are different type of placeholders, these placeholders are replaced in a specific order.

Including Workflow Variables

You can also substitute upstream variables into the output by using {var:varname}. This dynamic placeholder can be used in the Copy to Clipboard, Large Type and Write Text File outputs.

Find out more about using Variables in workflows.

Advanced Snippets and Dynamic Inputs

If a standard snippet or dynamic placeholders aren't suitable, the Snippet Triggers workflow object provides much more flexibility.

Take a look at the tutorial on using Snippet Triggers with dynamic text input, which walk you through creating a snippet where you can enter free text or select from a pre-defined list of options.

Need to transform your clipboard content in a more complex way? Take a look at the Workflows' Transform Utility object, which allows you to manipulate text content in more ways.

Latest Blog Post:

Alfred 4 is Coming in June!

CacheFly Campaign Monitor

"Alfred" is a registered trademark of Running with Crayons Ltd. ©2019 Running with Crayons Ltd. All rights reserved.

Terms & Conditions, Privacy Policy, Cookies.