Scripting Portmanteau
Portmanteau has an AppleScript dictionary. Scripts (and tools that run them: Shortcuts’ Run AppleScript action, Automator, Keyboard Maestro and so on) can read and search your notes, create new ones, and append to existing ones. Open the dictionary in Script Editor with File ▸ Open Dictionary…
The first time another app controls Portmanteau, macOS asks permission (System Settings ▸ Privacy & Security ▸ Automation).
What scripts see
Your library as you see it: notebooks, their notes, and each note’s attachments. A note has an id, name (title), body (Markdown), plain text, creation and modification dates, tags, web address, imported from, a link (portmanteau://note/…), in trash and notebook. Notes in the Trash appear as trashed notes.
Not exposed: recognized text, note history and sync state. Attachments’ file contents aren’t returned.
Reading and searching
tell application "Portmanteau"
set found to search "boarding pass"
repeat with n in found
log (name of n)
end repeat
end tell
search finds what the search field finds, best first, at most 500 notes. Limit it to a notebook with search "plan" in notebook "Work".
tell application "Portmanteau"
get name of every note of notebook "Work"
show note id "…"
end tell
Names aren’t unique. If two notebooks are called “Work”, notebook "Work" is an error that lists both ids. Use every notebook whose name is "Work", or an id, which is always exact.
Creating notes
tell application "Portmanteau"
create note in notebook "Inbox" titled "Call back" containing "Thursday, before noon." & linefeed & "Ask about the invoice."
end tell
The notebook is required: there is no default, and what’s selected never decides. Optional parts:
titled "…": otherwise the first line of the text, or the first file’s name.containing "…": plain text, a paragraph per line.containing markdown "…": Markdown, after any text. It can’t refer to attachments; attach files instead.attaching {file "Macintosh HD:Users:you:Desktop:scan.pdf"}: files, after the text. Pictures are shown at a sensible width.
Appending
tell application "Portmanteau"
append note id "…" containing "Followed up on Friday."
end tell
Text and files go at the end of the note, after a horizontal rule. You can’t append to a note in the Trash.
Changes are undoable, and limited on purpose
Scripts can create and append, and nothing else: no rewriting titles or bodies, moving, trashing or deleting. Changing a note’s text from outside is where data gets lost (a stale read written back over newer work). Every scripted change goes through Edit ▸ Undo like your own.
Scripts never open dialogs or change what you’ve selected. Errors go back to the script, and show brings a note into view when you want that.