Pasteboard

A pasteboard (also referred to as “the clipboard”) temporarily holds representations of items of different types for transfer between different applications or different locations in the application.

Class Properties

Class Functions

Instance Properties

var str = Pasteboard.general.string if(str){console.log(str)}
Pasteboard.general.string = "How Now Brown Cow" console.log(Pasteboard.general.string)
var tempClip = Pasteboard.makeUnique() tempClip.string = "The rain in Spain falls mainly on the plain." console.log(tempClip.string)

NOTE: altering the content of a unique pasteboard does not effect the contents of the user pasteboard (main clipboard).

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(function(urlObj){ console.log(urlObj.string) urlObj.open() }) fileSaverPromise.catch(function(err){ console.error(err.message) }) }

Instance Functions

if(Pasteboard.general.hasImages){ var data = Pasteboard.general.dataForType(TypeIdentifier.png) var wrapper = FileWrapper.withContents('IMG-CLIP.png', data) var filesaver = new FileSaver() var fileSaverPromise = filesaver.show(wrapper) fileSaverPromise.then(function(urlObj){ console.log(urlObj.string) urlObj.open() }) fileSaverPromise.catch(function(err){ console.error(err.message) }) }
var targetType = new TypeIdentifier("public.utf8-plain-text") if(Pasteboard.general.availableType([targetType])){ var items = Pasteboard.general.items var i for (i = 0; i < items.length; i++) { var data = items[i].dataForType(targetType) if(data){ console.log(data.toString()) break } } var wrapper = FileWrapper.withContents('Pasteboard.txt', data) var filesaver = new FileSaver() var fileSaverPromise = filesaver.show(wrapper) fileSaverPromise.then(function(urlObj){ console.log(urlObj.string) urlObj.open() }) fileSaverPromise.catch(function(err){ console.error(err.message) }) }

Pasteboard.Item Class

Nullam id dolor id nibh ultricies vehicula ut id elit. Cras mattis consectetur purus sit amet fermentum. Curabitur blandit tempus porttitor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras mattis consectetur purus sit amet fermentum. Donec ullamcorper nulla non metus auctor fringilla.

Instance Properties

The properties of an instance of the Pasteboard.Item class:

Instance Functions

The functions used to manipulate an instance of the Pasteboard.Item class:

var img64 = "iVBORw0KGgoAAAANSUhEUgAAABMAAAASCAYAAAC5DOVpAAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAgtpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IlhNUCBDb3JlIDUuNC4wIj4KICAgPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4KICAgICAgPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIKICAgICAgICAgICAgeG1sbnM6dGlmZj0iaHR0cDovL25zLmFkb2JlLmNvbS90aWZmLzEuMC8iPgogICAgICAgICA8dGlmZjpSZXNvbHV0aW9uVW5pdD4yPC90aWZmOlJlc29sdXRpb25Vbml0PgogICAgICAgICA8dGlmZjpDb21wcmVzc2lvbj41PC90aWZmOkNvbXByZXNzaW9uPgogICAgICAgICA8dGlmZjpPcmllbnRhdGlvbj4xPC90aWZmOk9yaWVudGF0aW9uPgogICAgICAgICA8dGlmZjpQaG90b21ldHJpY0ludGVycHJldGF0aW9uPjI8L3RpZmY6UGhvdG9tZXRyaWNJbnRlcnByZXRhdGlvbj4KICAgICAgPC9yZGY6RGVzY3JpcHRpb24+CiAgIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+CobSriQAAAGeSURBVDgRjZS/K4VhFMfv9TOykM0iPzJgkDIYDCyUxSIpi0kZDAaDSUb8CQYmKWGQRXdQykgMSukOlIVIym8+3+s5b8frva5Tn3vOc873fd7ned7z3HTqb2uh3ABlcAVH8Ab/tmKUE3AOn/AKZyG+wS9BNRS0WhQHoEmMDPGsGyt/DV2Q16qonIJNYn6KXGtC/pFcByTaClmbwPv6oLZt+9oFtYpQj1w70Qd4oeLjSJFKLSTUpZk2TUkIxvGH8GSF4NfdeI24040tHCXQR4lMZ6XP3hRlCgeVSFZBq6vz8oeQvMMP+UKeWP13AnYs3V6nXrKC/CLYEXid4mGwl9szfV6k7raC+V4vCLFuglrCNObbvHYrJtB2S73AxZsx7b1pi4JIAm+7DLR12QDMQFoDbPvbRb87RKbNJbUKNaAte4RYL5oH6z89VAO6crrs0r7Djy0yzlkPv3rDCzTDHtjk5rPkdCf3Q20On9fGqGThEmyCuH+mpp5cBjsmwmTTCpMuvE16S30y6VE71HhN/2n9MAiNUA5abQY2QF/7l30BWpSQgTjp6dQAAAAASUVORK5CYII=" var imgData = Data.fromBase64(img64) var item = new Pasteboard.Item() item.setDataForType(imgData,TypeIdentifier.jpeg) //Pasteboard.general.items = [item] Pasteboard.general.clear() Pasteboard.general.addItems([item])

Replace String on Pastebord

Here's an Omni Automation plug-in that replaces the designated string in the text currently on the global Pasteboard:

/*{ "type": "action", "targets": ["omnifocus","omnigraffle","omnioutliner","omniplan"], "author": "Otto Automator", "identifier": "com.omni-automation.all.replace-string-on-pasteboard", "version": "1.0", "description": "This action will replace the provided string with the provided replacement string in the text currently on the user pasteboard. NOTE: the resulting text will be in plain-text format.", "label": "Replace String on Pasteboard", "shortLabel": "Find-Change Clipboard" }*/ (() => { var action = new PlugIn.Action(function(selection, sender){ // action code var textInputField01 = new Form.Field.String( "textInput01", "Search for", null ) var textInputField02 = new Form.Field.String( "textInput02", "Replace with", null ) var checkSwitchField = new Form.Field.Checkbox( "checkboxSwitch", "Case-insensitive and word-only", true ) var inputForm = new Form() inputForm.addField(textInputField01) inputForm.addField(textInputField02) inputForm.addField(checkSwitchField) var formPrompt = "Search and replace text on the clipboard:" var buttonTitle = "Continue" formPromise = inputForm.show(formPrompt,buttonTitle) inputForm.validate = function(formObject){ var inputText01 = formObject.values['textInput01'] var inputText01Status = (!inputText01)?false:true var inputText02Status = true var validation = (inputText01Status && inputText02Status) ? true:false return validation } formPromise.then(function(formObject){ var searchString = formObject.values['textInput01'] var replacementString = formObject.values['textInput02'] if (!replacementString){replacementString = ""} var checkboxStatus = formObject.values['checkboxSwitch'] var contentString = Pasteboard.general.string if (checkboxStatus){ var re = new RegExp(`\\b${searchString}\\b`, 'gi') var newString = contentString.replace(re,replacementString) } else { var re = new RegExp(`${searchString}`, 'g') var newString = contentString.replace(re,replacementString) } Pasteboard.general.string = newString }) formPromise.catch(function(err){ console.error("form cancelled", err.message) }) }); action.validate = function(selection, sender){ // validation code return (Pasteboard.general.hasStrings) }; return action; })();
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.

DISCLAIMER