Copying text to the system clipboard in Javascript AIR applications

Filed under: AIR, jQuery, projects, Shrinkadoo

comments (2) Views: 9,317

As I'm researching adding features to Shrinkadoo, a jQuery / ColdFusion powered AIR application, I'm learning all sorts of new things about the most excellent AIR framework. One of those things is the ability read to / write from the system clipboard. The ability to copy items to the clipboard is so ubiquitous that it's hard NOT to include it in your app. So let's take a quick peek at how to accomplish this in JavaScript based AIR applications.

The first thing we need to do is to create a new reference to the clipboard. In AIR, there are two types of clipboard: the system clipboard, and the AIR clipboard. We'll only concern ourselves with the system clipboard for now.


// create a new clipboard object, a static value
var cb = air.Clipboard.generalClipboard;

Now that we have a new clipboard object, we need to import the available clipboard formats. There are currently 6 static values, but again we'll only be concerning ourselves with one of them...TEXT_FORMAT


// retrieve the value for text formatted clipboard values
var cbFormat = air.ClipboardFormats.TEXT_FORMAT;

Finally, we set our string to the clipboard


// set the string data into the clipboard
cb.setData(cbFormat,myString);

It's a pretty simple process


// the original string
var myString = 'AIR is great!';
// create a new clipboard object, a static value
var cb = air.Clipboard.generalClipboard;
// retrieve the value for text formatted clipboard values
var cbFormat = air.ClipboardFormats.TEXT_FORMAT;
// set the string data into the clipboard
cb.setData(cbFormat,myString);

Look for more one-off AIR tips as I work through adding features to Shrinkadoo. Also, make sure to check out copy and paste in Shrinkadoo, coming soon.

Amazon logo

If this article was interesting, or helpful, or even wrong, please consider leaving a comment, or buying something from my wishlist. It's appreciated!

comments powered by Disqus
coach outlet online jordan 13 grey toe beats by dre cyber monday michael kors black friday beats by dre cyber monday jordan 6 black infrared north face cyber monday michael kors cyber monday north face black friday coach outlet black infrared 23 13s north face cyber monday jordan 6 black infrared north face black friday coach cyber monday jordan 11 legend blue north face cyber monday black infrared 6s lebron 12 north face black friday jordan 11 legend blue louis vuitton outlet jordan 13 grey toe grey toe 13s beats by dre black friday coach black friday jordan 13 grey toe coach cyber monday uggs black friday jordan 13 black infrared 23 uggs cyber monday barons 13s uggs black friday beats by dre cyber monday black infrared 6s jordan 13 bred jordan 13 black infrared 23 north face black friday black infrared 6s jordan 11 legend blue michael kors black friday jordan 13 grey toe coach black friday michael kors black friday michael kors cyber monday beats by dre cyber Monday north face cyber monday coach black friday michael kors cyber monday beats by dre cyber Monday north face black friday beats by dre black friday lululemon black friday uggs black friday jordan 13 bred coach cyber monday beats by dre black friday uggs black friday coach black friday black infrared 6s