Plug-In: Reset Paragraph Attributes
A plug-in for restoring the paragraph attributes of the note of the selected project or task to their default values.
IMPORTANT: Attribute changes are applied to all of the note text, not just a selection.
Here is a description of each of the paragraph attributes:
- Alignment (TextAlignment) • The text alignment of the paragraph. Natural text alignment is realized as left or right alignment depending on the line sweep direction of the first script contained in the paragraph.
- First Line Head Indent (Number) • The indentation of the first line of the paragraph. A paragraph’s “head” is the side from which you read. This property contains the distance (in points) from the leading margin of a text container to the beginning of the paragraph’s first line. This value is always nonnegative.
- Head Indent (Number) • The indentation of the paragraph’s lines other than the first. A paragraph’s “head” is the side from which you read. This property contains the distance (in points) from the leading margin of a text container to the beginning of lines other than the first. This value is always nonnegative.
- Tail Indent (Number) • If positive, this value is the distance from the leading margin (for example, the left margin in left-to-right text). If 0 or negative, it’s the distance from the trailing margin.
- Line Height Multiple (Number) • The natural line height of the paragraph is multiplied by this factor (if positive) before being constrained by minimum and maximum line height. The default value of this property is 0.0.
- Line Spacing (Number) • The distance in points between the bottom of one line fragment and the top of the next. This value is always nonnegative.
- Spacing (Number) • The space after the end of the paragraph. This property contains the space (measured in points) added at the end of the paragraph to separate it from the following paragraph. This value is always nonnegative. The space between paragraphs is determined by adding the previous paragraph’s Paragraph Spacing and the current paragraph’s Paragraph Spacing Before.
- Spacing Before (Number) • The distance between the paragraph’s top and the beginning of its text content. This property contains the space (measured in points) between the paragraph’s top and the beginning of its text content. The default value of this property is 0.0.
Return to: OmniFocus Plug-In Collection
Reset Paragraph Attributes
/*{
"type": "action",
"targets": ["omnifocus"],
"author": "Otto Automator",
"identifier": "com.omni-automation.of.note-paragraph-defaults",
"version": "1.2",
"description": "This plug-in will format the rich text of the note of the selected project or task.",
"label": "Note Paragraph Defaults",
"shortLabel": "Paragraph Defaults",
"paletteLabel": "Paragraph Defaults",
"image": "parkingsign.circle"
}*/
(() => {
var action = new PlugIn.Action(function(selection, sender){
// action code
// selection options: tasks, projects, folders, tags, allObjects, databaseObjects
var item = selection.databaseObjects[0]
// REVEAL NOTE
tree = document.windows[0].content
tree.nodeForObject(item).expandNote(false)
// PARAGRAPH ATTRIBUTES
var pAtts = [
Style.Attribute.ParagraphBaseWritingDirection,
Style.Attribute.ParagraphAlignment,
Style.Attribute.ParagraphFirstLineHeadIndent,
Style.Attribute.ParagraphHeadIndent,
Style.Attribute.ParagraphLineHeightMultiple,
Style.Attribute.ParagraphLineSpacing,
Style.Attribute.ParagraphMaximumLineHeight,
Style.Attribute.ParagraphMinimumLineHeight,
Style.Attribute.ParagraphSpacing,
Style.Attribute.ParagraphSpacingBefore,
Style.Attribute.ParagraphDefaultTabInterval,
Style.Attribute.ParagraphTabStops,
Style.Attribute.ParagraphTailIndent
]
// CREATE VIRTUAL TEXT OBJECT CONTAING CURRENT NOTE
var noteObj = new Text("", baseStyle)
noteObj.replace(noteObj.range, item.noteText)
// GET ATTRIBUTE RUNS
runRanges = noteObj.ranges(TextComponent.AttributeRuns)
// PROCESS ATTRIBUTE RUNS
runRanges.forEach(range => {
runStyle = noteObj.styleForRange(range)
pAtts.forEach(att => {
runStyle.set(att, att.defaultValue)
})
})
// REPLACE NOTE WITH VIRTUAL OBJECT
item.noteText.replace(item.noteText.range, noteObj)
});
action.validate = function(selection, sender){
// validation code
// selection options: tasks, projects, folders, tags, allObjects
return (selection.tasks.length === 1 || selection.projects.length === 1 )
};
return action;
})();