Accepts
App Store Apps, Articles, Contacts, Dates, Email Addresses, WFFolderContentItem, Files, Images, iTunes Products, Locations, Map Links, Media, PDFs, Phone Numbers, Rich Text, Safari Web Pages, Text and URLs
COMMENT
Bear template expander for Mac, iPhone and iPad
2024-11-01 at 10:47 EDT
Make templates as Bear notes with tag: #.template
See sample template text at bottom of this shortcut.
{{date}} in templates will expand to today’s date/time (yyyy-MM-dd, HH:mm)
{{datetag}} in templates will become a tag: #yyyy/MM
(or change date/time format in code below to suit your needs)
{{key}} tags in template will be expanded to values,
set values in Dictionary below to suit your needs.
DICTIONARY

Dictionary
TEXT
#.template

Text
VARIABLES
Set variable
templateTag
to
Text
COMMENT
Get list of templates to choose (lists all notes containing ‘templateTag’):
MISSING
Under Construction
SCRIPTING

Chosen Item
DOCUMENTS
Replace
bear://x-callback-url/open-note?id=
with
World
in
Selected Item

Updated Text
VARIABLES
Set variable
noteID
to
Updated Text
COMMENT
Get chosen template note text from Bear:
BEAR
Under Construction
VARIABLES
Set variable
noteText
to
Note
COMMENT
Remove template tag (and line break above it):
DOCUMENTS
Replace
templateTag
with
World
in
noteText

Updated Text
VARIABLES
Set variable
noteText
to
Updated Text
COMMENT
Insert date/time if {{date}} is used in template:
DOCUMENTS
Replace
{{date}}
with
Current Date
in
noteText

Updated Text
VARIABLES
Set variable
noteText
to
Updated Text
DOCUMENTS
Replace
{{datetag}}
with
#
Current Date
in
noteText

Updated Text
VARIABLES
Set variable
noteText
to
Updated Text
COMMENT
Remove \ from \#tags to unhide tags in template:
DOCUMENTS
Replace
\#
with
#
in
noteText

Updated Text
VARIABLES
Set variable
noteText
to
Updated Text
COMMENT
Parse ‘my-dict’ and replace {{keys}} in template with key value pairs (from dictionary at top of shortcut):
SCRIPTING
Repeat with each item in
my-dict

Repeat Results
SCRIPTING
Get
Value
for
Repeat Item
in
my-dict

Dictionary Value
DOCUMENTS
Replace
{{
Repeat Item
}}
with
Dictionary Value
in
noteText

Updated Text
VARIABLES
Set variable
noteText
to
Updated Text
SCRIPTING
End Repeat

Repeat Results
COMMENT
Create new note in Bear based on chosen template:
BEAR
Under Construction
SAFARI
Open
Note
SCRIPTING
Exit shortcut with
Result
COMMENT
# Sample Template
#.template
Notes with this tag will appear in template list, but tag will be removed from new notes. Important! This tag should be placed on it’s own line!
## if you want to include a tag with current month or date, include:
{{datetag}}
(Set date format in shortcut)
## Current Date
Today: {{date}} (place anywhere in note)
(Set date format in shortcut)
## Expandable Keys
Keys will be expanded to corresponding values if they appear in dictionary at top of shortcut (place anywhere in note).
{{name}}
{{email}}
{{addres}}
{{phone}}
{{anything)
If dictionary keys do not appear in template they are just ignored.
## Hidden (escaped) tags in template, that will be revealed in new notes after running this shortcut:
\#my-tag1 \#my new tag2#