Runtimes & APIs
URL Templates Engine
Web searches, documentation lookups, and deep links with percent-encoded placeholder tokens.
On this page (5 sections)
The URL templates engine (URLTemplateAction) powers instant web search, documentation lookup, and custom URI scheme deep-linking actions.
Execution Mechanism#
When a user selects a URL template action:
- Text Extraction: Selected text is trimmed of leading and trailing whitespace.
- Placeholder Substitution:
TextPlaceholderEnginesubstitutes template tokens with percent-encoded query parameters. - URL Resolution: The resulting string is parsed into a
URLobject and returned asActionResult.openURL(url). - Platform Launch:
DefaultActionResultHandleropens the URL viaNSWorkspace.shared.open(url).
Supported Placeholders#
TextPlaceholderEngine replaces the following template tokens:
Regex Pattern Gating & Visibility Rules#
URL template actions support regex gating (via regexPattern or ExtensionActionRules). When evaluated, enablement and capture extraction delegate to ActionVisibility:
swift
@MainActor
public func isEnabled(for context: ActionContext) -> Bool {
guard let rules else {
return ActionVisibility.isEnabled(
requirements: nil,
legacyRegex: regexPattern,
context: context
).enabled
}
return rules.resolveVisibility(for: context).enabled
}Common Regex Examples#
- Match URLs Only:
^https?://\\S+$ - Match Issue Tracker Numbers:
^#[0-9]+$or^[A-Z]+-[0-9]+$ - Match IP Addresses:
^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$
Practical Examples#
json
{
"id": "builtin.search.google",
"title": "Search Google",
"icon": "symbol:magnifyingglass",
"url": "https://www.google.com/search?q={query}"
}json
{
"id": "action.github.repo",
"title": "Open GitHub Repo",
"icon": "symbol:book",
"url": "https://github.com/{query}",
"regex": "^[a-zA-Z0-9_-]+/[a-zA-Z0-9_-]+$"
}