A generic bag of bytes. Mainly useful to be interpreted / converted to some other type.

Instance Properties

Instance Functions

Functions for converting instances of the Data class into instances of the String class:

Class Functions

Functions for converting instances of the String class into instances of the Data class:

String to Base64 Encoded String

var encodedString = Data.fromString("How Now Brown Cow").toBase64() //--> "SG93IE5vdyBCcm93biBDb3c="


Here’s an Omni Automation script for creating a new task in OmniFocus with the current OmniOutliner document as an attachment. The script uses the integrated URL support in OmniFocus to create and run a URL link for creating tasks.

In this example, the processed Data object is the extracted value of the contents property of the created FileWrapper instance (line 5). Note that the toBase64() function of the Data class to convert the contents of the file wrapper into a format that can be used in a URL.

New OmniFocus Task with Outline Attachment

var taskName = document.name var wrapperPromise = document.makeFileWrapper(taskName) wrapperPromise.then(function(wrapper){ var attachmentName = encodeURIComponent(wrapper.preferredFilename) var encodedData = wrapper.contents.toBase64() taskName = encodeURIComponent(taskName) urlStr = "omnifocus://localhost/add?name=" + taskName + "&attachment=" + encodedData + "&attachment-name=" + attachmentName URL.fromString(urlStr).open() }) wrapperPromise.catch(err => { console.log(err.message) })

Here’s an example script that exports the current text on the Pasteboard (clipboard) to a file. The example uses the fromString() of the Data class to convert the passed text to a data object that can be written to file.

NOTE: Since the Pasteboard class is a class shared by all Omni applications, this script will work in any Omni application:

Save the Clipboard Text to File

if(Pasteboard.general.hasStrings){ var data = Data.fromString(Pasteboard.general.string) var wrapper = FileWrapper.withContents('Pasteboard.txt', data) var filesaver = new FileSaver() var fileSaverPromise = filesaver.show(wrapper) fileSaverPromise.then(urlObj => { console.log(urlObj.string) urlObj.open() }) fileSaverPromise.catch(err => { console.error(err.message) }) }