An instance of the FileSaver class enables the user to save one or more instances of the FileWrapper class to disk using the system-provided file picking interface.


Here are the properties of the FileSaver class.


The mechanism for creating a new instance of the FileSaver class.

Instance Functions

The functions that can be executed on an instance of the FileSaver class.


Saving/Exporting a Document

The following Omni Automation script demonstrates how to save an OmniPlan document to file. The same procedures are used by all Omni applications to export data and documents to file.

Detailed documentation regarding the FileType class, and its use to generate application-specific FileWrappers, can be found in the FileType topic.

// Create File Wrapper and File Type fileTypeID = 'com.omnigroup.omniplan2.planfile' defaultName = "" wrapper = document.fileWrapper(fileTypeID) if(defaultName){wrapper.preferredFilename = defaultName} filetype = new FileType(fileTypeID) // Create and Show File Saver filesaver = new FileSaver() filesaver.message = "Choose the location for the saved file:" // macOS filesaver.nameLabel = "Name:" // macOS filesaver.prompt = "Continue" // macOS filesaver.types = [filetype] fileSaverPromise = // Process File Saver Result fileSaverPromise.then(function(urlObj){ console.log(urlObj.string) }) fileSaverPromise.catch(function(err){ console.log(err.message) })

 02  The FileType identifier string of the file type to be saved or exported to file.

 03  An instance of the FileWrapper class is created for the OmniPlan document by calling the fileWrapper(…) method on the document class and passing in the stored FileType identifier string. The resulting file wrapper is stored int eh variable: wrapper

 04  The suggested name to be used for the saved file is assigned as the value of the preferredFilename property of the created file wrapper instance.

 05  The FileType identifier string is again used to create an instance of the FileType class, which is stored in the variable: filetype

 08  A new instance of the FileSaver class is stored in the variable: filesaver

 09-11  On macOS, the save dialog can be customized with a user prompt, name input lable, and approval button title. iOS does not offer these options.

 12  The value of the types property of the FileSaver instance is an array of the file types that will be allowed to be saved. By setting the file type to the previously created file type object, the adding of the correct name extenstion to the saved/exported file name will be done automatically, requiring no input by the user.

 13  To display the save dialog to the user, the show(…) method is called on the FileaSaver instance while passing in the created FileWrapper instance. The result of this command is a JavaScript promise object that represents the completion or cancellation of the dialog by the user.

 16-18  The results of a successful completion of the save dialog by the user will handled through the use of the then(…) function called on the stored promise object. A URL object representing the saved file will be automatically passed as input into the function. Place your statements for processing the passed URL object within this handler. In this example, the URL string is extracted from the URL object and logged in the Console.

 20-22  A cancelation of the save dialog by the user can be handled by the optional catch(…) method called on the stored promise instance. The error object for the save dialog will be passed as input to this function. Place any statements for dealing with the cancellation within this function.

Multiple Exports

In an application such as OmniGraffle, the need to export multiple instances of a canvas in various formats, in not an unusal occurence. The FileWrapper class includes a function for creating a folder wrapper that contains other file wrappers as its contents. The folder wrapper is passed to the FileSaver instance and when executed, a new directory containing the exported files is created on disk.

In the following script example, the current OmniGraffle canvas is exported as both an image in PNG format, and as a PDF file, both placed within a created directory.

cnvsName =[0] // Create file types and wrappers PNGtypeID = "public.png" PDFtypeID = "com.adobe.pdf" PNGwrapper = document.fileWrapper(PNGtypeID) PNGwrapper.preferredFilename = cnvsName + ".png" PNGfileType = FileType.png PDFwrapper = document.fileWrapper(PDFtypeID) PDFwrapper.preferredFilename = cnvsName + ".pdf" PDFfileType = FileType.pdf types = [PNGwrapper, PDFwrapper] fldrwrapper = FileWrapper.withChildren("Export Folder",types) folderType = new FileType("public.folder") // Create and Show File Saver filesaver = new FileSaver() filesaver.message = "Choose the location for the export folder:" // macOS filesaver.nameLabel = "Name:" // macOS filesaver.prompt = "Continue" // macOS filesaver.types = [folderType,PNGfileType,PDFfileType] fileSaverPromise = // Process File Saver Result fileSaverPromise.then(function(urlObj){ console.log(urlObj.string) }) fileSaverPromise.catch(function(err){ console.log(err.message) })

 01  Get the name of the current canvas in the OmniGraffle document. NOTE: if this example script was wrapped within an action plugIn template, use the canvas property of the passed-in selection object: selection.canvas

 04-14  Create file wrappers and file types for the desired export items.

 07   10  Since the canvas title is to be used as the name for each of the exported files, include the name extension in the name to avoid a naming conflict error. Usually, file extensions are not required in the name and are automatically added by the file save instance.

 14  Note the inclusion of the folder file type, which will be added to the beginning of the types array passed to the file saver instance.

 17  Create a new instance of the FileSaver class.

 18-20  Set the values of the disdplay properties of the file saver instance.

 21  Assign the array of types as the value of the file saver’s types property. Note that the list of types begins with the file type of the folder that is to contain the exported images.

 22  Display the FileSaver dialog for the user to choose the location in which the new folder will be created. When the selection is made by the user, the dialog will close and the folder containing the exported items will be created.

Using the FileSaver with Shortcuts App

Here is an example Omni Automation action plug-in that calls a Shortcuts workflow to process a saved OmniPlan file. You can adapt this action to work with any of the Omni suite of applications.

/*{ "type": "action", "targets": ["omniplan"], "author": "Action Author", "identifier": "com.youOrCompany.actionName", "version": "1.0", "description": "Action Description", "label": "Menu Item Title", "paletteLabel": "Toolbar Item Title" }*/ var _ = function(){ var action = new PlugIn.Action(function(selection, sender){ // action code // selection options: project, tasks, resources // Change this value to match the file type to export var aFileTypeIdentifer = 'com.omnigroup.omniplan2.planfile' // Create File Wrapper and File Type wrapper = document.fileWrapper(aFileTypeIdentifer) filetype = new FileType(aFileTypeIdentifer) // Create and Show File Saver filesaver = new FileSaver() filesaver.message = "Choose the location for the saved file:" // macOS filesaver.nameLabel = "Name:" // macOS filesaver.prompt = "Continue" // macOS filesaver.types = [filetype] fileSaverPromise = // Process File Saver Result fileSaverPromise.then(function(urlObj){ encodedFileURLString = encodeURIComponent(urlObj.string) // change the name to match the name of the targeted Shortcuts workflow workflowName = "Processing Workflow" workflowName = encodeURIComponent(workflowName) callingURLString = "shortcuts://run-workflow?name=" + workflowName + "&input=text&text=" + encodedFileURLString URL.fromString(callingURLString).call(function(reply){ console.log(reply) } }) fileSaverPromise.catch(function(err){ console.log(err.message) }) }); action.validate = function(selection, sender){ // validation code // selection options: project, tasks, resources return true }; return action; }(); _;

This webpage is in the process of being developed. Any content may change and may not be accurate or complete at this time.