Some of the most useful automated processes are those that involve more than one application, requiring many calculated steps, and are guided by user input. This workflow for choosing a photo and adding to an outline is one such example.
Apple’s Workflow application handles the selection and processing of the chosen image, and then passes the image data to an Ommi Automaton script for inserting the image into a new row in an open outline document.
And the best part is that is all happens automatically in seconds! (Watch)
The Omni Automation Script
The automation scenario demonstrated by this example is in two parts, the first of which is handled by the Workflow app performing the following tasks:
Prompt the user to select a sizing option for the images to process.
Prompt the user to select images from the active Photos library.
Process each of the selected images using the following steps:
Store the chosen image’s name, file extension, and width dimension in variables.
Scale the chosen image (if required).
Crop the chosen image (if required).
Convert the image data into a base64 string.
Insert the base64 string and stored data into a pre-encoded Omni Automation script URL.
Execute the script URL.
With those tasks accomplished, it is up to the launched Omni Automation script to:
Check the OmniOutliner document for a column titled “Image” in which to place the image, and if the column is not found, inform the user and stop the script.
Convert the base64 string data into an OmniOutliner text attachment object.
Add a new row to the end of the outline.
Insert the stored name and image into the appropriate row cells.
Here is the Omni Automation script:
try {
var imageName = 'XXXXX'
var imageFileExtension = 'YYYYY'
var image64Str = 'ZZZZZ'
var colTitle = 'Image'
columnTitles = columns.map(function(col){
return col.title
})
if(columnTitles.indexOf(colTitle) === -1){
alertMsg = 'There is no column titled “' + colTitle + '” in this outline.'
var alert = new Alert('Missing Column',alertMsg)
alert.addOption('Cancel')
alert.show(function(result){})
} else {
imageData = Data.fromBase64(image64Str)
imageFileName = imageName + '.' + imageFileExtension
wrapper = FileWrapper.withContents(imageFileName,imageData)
textObj = Text.makeFileAttachment(wrapper, document.outline.baseStyle)
rootItem.addChild(
null,
function(item){
item.topic = imageName
item.setValueForColumn(textObj,columns.byTitle('Image'))
}
)
}
} catch (err){
var alert = new Alert('Script Error',err)
alert.show(function(result){})
}
Pic to Row
01
try {
02
varimageName = 'XXXXX'
03
varimageFileExtension = 'YYYYY'
04
varimage64Str = 'ZZZZZ'
05
varcolTitle = 'Image'
06
columnTitles = columns.map(function(col){
07
returncol.title
08
})
09
if(columnTitles.indexOf(colTitle) === -1){
10
alertMsg = 'There is no column titled “' + colTitle + '” in this outline.'
01-30 The script is wrapped in an error handler that displays, in OmniOutliner, a dialog with the error message.
02-04 During the workflow execution, the placeholders (XXXXX, YYYYY, ZZZZZ) are replaced with the chosen image’s name, file extension, and base64 data. In these script statements, those items are placed into declared variables.
05 The name of the column in which to insert the image.
06-08 Get a list of the column titles.
09 Check to see if the list of column titles contain the designated column title.
10-13 If the list of column titles does not contain the designated title, display an error message to the user.
15 Create an instance of the Data class from the base64 string.
16-17 Create an instance of the FileWrapper class using the image name and extension, and the image data object.
18 Create a Text Attachment object using the FileWrapper instance.
19-25 Add a new row at the default postion (end of rows) and insert the image name in the topic column and the image in the designated column.
The Workflow
As described previously, the Workflow document shown below does some “heavy lifting” in this automation scenario, by performing the following tasks:
Prompt the user to select a sizing option for the images to process.
Prompt the user to select images from the active Photos library.
Process each of the selected images using the following steps:
Store the chosen image’s name, file extension, and width dimension in variables.
Scale the chosen image (if required).
Crop the chosen image (if required).
Convert the image data into a base64 string.
Insert the base64 string and stored data into a pre-encoded Omni Automation script URL.
Execute the script URL.
You can get this workflow here, and download the example OmniOutliner document here.
UNDER CONSTRUCTION
This webpage is in the process of being developed. Any content may change and may not be accurate or complete at this time.