OO-PG0021
Plug-In: Metadata Defaults
Requires OmniOutliner v6
Sets the document metadata for: authors, organizations, projects, keywords, and copyright. Input values are stored between executions of this plug-in.
Use commas only to delimit multiple entries for all fields except copyright, which is a single text string.
TIP: OmniOutliner document metadata is discoverable using Spotlight. Search for: OmniOutliner "Metadata term or phrase"
Metadata Defaults
/*{"type": "action","targets": ["omnioutliner"],"author": "Otto Automator","identifier": "com.omni-automation.oo.metadata-defaults","version": "1.0","description": "Sets the document metadata. Values are stored between executions of this plug-in.","label": "Metadata Defaults","shortLabel": "Metadata","paletteLabel": "Metadata","image": "tablecells.fill.badge.ellipsis"}*/(() => {var preferences = new Preferences() // NO ID = PLUG-IN IDfunction splitAndTrim(inputString) {if (typeof inputString !== "string") return [];return inputString.split(",") // split by commas.map(s => s.trim()) // remove leading/trailing whitespace.filter(s => s.length > 0); // remove empty entries (optional)}function encodeCommas(input) {if (typeof input !== "string") return "";return input.replace(/,/g, "%2C");}function decodeCommas(input) {if (typeof input !== "string") return "";return input.replace(/%2C/gi, ",");}function parseListField(str) {// Normalize null/undefined to empty stringif (!str || typeof str !== "string") return [];// Trim; if nothing remains, return []const trimmed = str.trim();if (trimmed === "") return [];// Use existing function to split into valuesreturn splitAndTrim(trimmed);}const action = new PlugIn.Action(async function(selection, sender){try {// READ PREFERENCESlet authorsStr = preferences.readString("authors") || "";let copyrightStr = preferences.readString("copyright") || "";let organizationsStr = preferences.readString("organizations") || "";let projectsStr = preferences.readString("projects") || "";let keywordsStr = preferences.readString("keywords") || "";// FORM FIELDSconst authorsInputField = new Form.Field.String("authorsStr","Author(s)",authorsStr);const organizationsField = new Form.Field.String("organizationsStr","Organization(s)",organizationsStr);const projectsField = new Form.Field.String("projectsStr","Project(s)",projectsStr);const copyrightInputField = new Form.Field.String("copyrightStr","Copyright",copyrightStr);const keywordsField = new Form.Field.String("keywordsStr","Keyword(s)",keywordsStr);const inputForm = new Form();inputForm.addField(authorsInputField);inputForm.addField(organizationsField);inputForm.addField(projectsField);inputForm.addField(copyrightInputField);inputForm.addField(keywordsField);inputForm.validate = function(formObject) {return true;};// PRESENT FORM TO USERconst formPrompt = "Metadata Defaults: (comma-delimit multiple items)";const buttonTitle = "Continue";const formObject = await inputForm.show(formPrompt, buttonTitle);// PROCESS RESULTS// AuthorsauthorsStr = formObject.values["authorsStr"] || "";console.log("authorsStr:", authorsStr);let authorsArray = parseListField(authorsStr);setMetadataValue(authorsArray, MetadataKey.authors);// OrganizationsorganizationsStr = formObject.values["organizationsStr"] || "";console.log("organizationsStr:", organizationsStr);let organizationsArray = parseListField(organizationsStr);setMetadataValue(organizationsArray, MetadataKey.organizations);// ProjectsprojectsStr = formObject.values["projectsStr"] || "";console.log("projectsStr:", projectsStr);let projectsArray = parseListField(projectsStr);setMetadataValue(projectsArray, MetadataKey.projects);// KeywordskeywordsStr = formObject.values["keywordsStr"] || "";console.log("keywordsStr:", keywordsStr);let keywordsArray = parseListField(keywordsStr);setMetadataValue(keywordsArray, MetadataKey.keywords);// Copyright (not an array)copyrightStr = formObject.values["copyrightStr"] || "";console.log("copyrightStr:", copyrightStr);setMetadataValue(copyrightStr, MetadataKey.copyright);// STORE PREFERENCESpreferences.write("authors", authorsArray.join(", "));preferences.write("organizations", organizationsArray.join(", "));preferences.write("projects", projectsArray.join(", "));preferences.write("keywords", keywordsArray.join(", "));preferences.write("copyright", copyrightStr);}catch (err) {if (!err.causedByUserCancelling){await new Alert(err.name, err.message).show();}}});action.validate = function(selection, sender){return (app.userVersion.atLeast(new Version("6")));};return action;})();