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; })();

Fetch Chart to Pasteboard

The following plug-in demonstrates how charts can be generated using an online service, and the resulting chart images be automatically placed on the Omni application’s pasteboard (clipboard) ready to be pasted.

The URL APIs from the QuickChart website (quickchart.io) are used to generate the chart images.

You can edit this plug-in to use data from the current Omni document as the data sets for the charts, instead of the provided example data sets.

/*{ "type": "action", "targets": ["omnifocus","omnigraffle","omnioutliner","omniplan"], "author": "Otto Automator", "identifier": "com.omni-automation.all.fetch-chart", "version": "1.0", "description": "This action generates a chart using the QuickChart (quickchart.io) APIs.", "label": "Fetch Chart Image", "shortLabel": "Fetch Chart" }*/ (() => { var action = new PlugIn.Action(function(selection, sender){ var menuItems = ["Doughnut","Bar","Pie","Radial Guage","Line Graph"] var menuIndexes = new Array() menuItems.forEach((item,index)=>{ menuIndexes.push(index) }) var menuElement = new Form.Field.Option( "menuElement", "Chart Type", menuIndexes, menuItems, 0 ) var inputForm = new Form() inputForm.addField(menuElement) var formPrompt = "Fetch an image from QuickChart (quickchart.io):" var buttonTitle = "Continue" formPromise = inputForm.show(formPrompt,buttonTitle) inputForm.validate = function(formObject){ return true } formPromise.then(function(formObject){ var menuIndex = formObject.values['menuElement'] var chosenChartType = menuItems[menuIndex] console.log('Chosen chart: ',chosenChartType) try { // QuickChart https://quickchart.io/ var url = "https://quickchart.io/chart?c=" var chartDataSets = [ "{type:'doughnut',data:{labels:['January','February','March','April','May'],datasets:[{data:[50,60,70,180,190]}]},options:{plugins:{doughnutlabel:{labels:[{text:'550',font:{size:20}},{text:'total'}]}}}}", "{type:'bar',data:{labels:['Q1','Q2','Q3','Q4'], datasets:[{label:'Users',data:[50,60,70,180]},{label:'Revenue',data:[100,200,300,400]}]}}", "{type:'pie',data:{labels:['January','February', 'March','April', 'May'], datasets:[{data:[50,60,70,180,190]}]}}", "{type:'radialGauge',data:{datasets:[{data:[70],backgroundColor:'green'}]}}", "{type:'line',data:{labels:['January','February', 'March','April', 'May'], datasets:[{label:'Dogs', data: [50,60,70,180,190], fill:false,borderColor:'blue'},{label:'Cats', data:[100,200,300,400,500], fill:false,borderColor:'green'}]}}" ] var chartDataSet = chartDataSets[menuIndex] var url = url + encodeURIComponent(chartDataSet) //URL.fromString(url).open() URL.fromString(url).fetch(data => { var item = new Pasteboard.Item() item.setDataForType(data,TypeIdentifier.png) Pasteboard.general.items = [item] var alert = new Alert(chosenChartType, "Chart on pasteboard.") alert.addOption("Done") alert.addOption("Website") alert.show(function(result){ if (result == 0){ console.log("Button 1") } else { var url = "https://quickchart.io" URL.fromString(url).open() } }) }) } catch(err){console.error(err.message)} }) formPromise.catch(function(err){ console.error("form cancelled", err.message) }) }); action.validate = function(selection, sender){ // validation code // selection options: tasks, projects, folders, tags, allObjects return true }; return action; })();

Doughnut:

chart-01

Line:

chart-02

Bar:

chart-03

Pie:

chart-04

Radial Guage:

chart-05
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