Plug-In: Set Graphic Opacity

Here is an Omni Automation plug-in for OmniGraffle that will change the opacity of the selected items (shapes, lines, and groups) to the percentage value provided by the plug-in user:

Return to: OmniGraffle Plug-In Collection

Set Opacity of Selected Items
  

/*{ "type": "action", "targets": ["omnigraffle"], "author": "Otto Automator", "identifier": "com.omni-automation.og.set-opacity-of-selection", "version": "1.1", "description": "This action will set the opacity of the selected graphics to the indicated percentage.", "label": "Set Opacity", "shortLabel": "Opacity", "paletteLabel": "Opacity", "image": "paintbrush.fill" }*/ (() => { function processStroke(item,opacity){ c = item.strokeColor newColor = Color.RGB(c.red, c.green, c.blue, opacity) item.strokeColor = newColor } function processFill(item,opacity){ c = item.fillColor newColor = Color.RGB(c.red, c.green, c.blue, opacity) item.fillColor = newColor } function processGroup(group,opacity,shouldIncludeStroke){ group.graphics.forEach(item => { if(item instanceof Shape){ processFill(item,opacity) if (shouldIncludeStroke){processStroke(item,opacity)} } if (item instanceof Line){ processStroke(item,opacity) } if (item instanceof Group){ processGroup(item,opacity,shouldIncludeStroke) } }) } var action = new PlugIn.Action(async function(selection, sender){ textInputField = new Form.Field.String( "textInput", null, "50" ) checkSwitchField = new Form.Field.Checkbox( "shouldIncludeStroke", "Apply opacity setting to shape’s stroke", true ) inputForm = new Form() inputForm.addField(textInputField) inputForm.addField(checkSwitchField) inputForm.validate = function(formObject){ inputText = formObject.values['textInput'] if (!inputText) {return false} var isnum = /^[0-9]+$/i.test(inputText) if (isnum){ var opacityValue = Number(inputText) return ((opacityValue >= 0 && opacityValue <= 100)? true:false) } return false } formPrompt = "Enter an opacity value (0-100):" buttonTitle = "Continue" formObject = await inputForm.show(formPrompt,buttonTitle) textValue = formObject.values['textInput'] console.log('textValue: ',textValue) shouldIncludeStroke = formObject.values['shouldIncludeStroke'] opacityValue = Number(inputText) * .01 selection.graphics.forEach(item => { if (item instanceof Shape){ processFill(item,opacityValue) if (shouldIncludeStroke){processStroke(item, opacityValue)} } if (item instanceof Line){ processStroke(item, opacityValue) } if (item instanceof Group){ processGroup(item, opacityValue, shouldIncludeStroke) } }) }); action.validate = function(selection, sender){ return (selection.graphics.length > 0) }; return action; })();