Full Access to the Clipboard

by Fraser Gordon on November 4, 2015 1 comment

LiveCode has had support for clipboard operations since the very early days, using the clipboard function and the clipboardData property. These are perfectly good if plain text, RTF and images are all you need to put on the clipboard but sometimes you need a little more than that.

David Simpson, writer of the popular FMPro Migrator software for migrating between FileMaker Pro and other database systems, found himself in that situation. As a LiveCode Business subscriber, he decided to sponsor the addition of more advanced clipboard access to LiveCode.

The first part of this is true low-level clipboard access; you can now access the clipboard at the operating system level using the rawClipboardData property:

lock the clipboard
put the keys of the rawClipboardData
unlock the clipboard

This will list the data types currently on the clipboard. Because it is at such a low level, the keys will be specific to the operating system.

Using the clipboard this way is a bit too fiddly if you don’t need the extra power it gives, so another way of accessing the clipboard has also been added: the fullClipboardData property. It eliminates the parts of the rawClipboardData that depend on the operating system and provides a more clipboardData-like interface.

For example, if the clipboard contains both an image and some text describing the image, the clipboard function will return "text" and the image won’t be accessible. In contrast, the keys of the fullClipboardData will include both "text" and "image". This means that if your data has multiple representations, all of them can be placed on the clipboard at the same time and the receiving application can pick the format that it prefers:

lock the clipboard
if "image" is among the keys of the fullClipboardData then
   -- Use the image
   put the fullClipboardData["image"] into ...
else if "text" is among the keys of the fullClipboardData then
   -- Use the text
   put the fullClipboardData["text"] into ...
end if
unlock the clipboard

Because the clipboard is shared with other applications and the new syntax allows you to put multiple representations on the clipboard, it is useful to be able to lock the clipboard to prevent other applications from overwriting it while you’re working with it. The new lock clipboard command can be used for this.

On most platforms, the clipboard and drag-and-drop are closely related. Similar enhancements have been added for the drag-and-drop clipboard using the rawDragData and fullDragData properties. Unlike the clipboard, no locking is required as a drag-and-drop operation provides the locking automatically.

These clipboard enhancements are available in LiveCode 8.0 Development Preview (DP) 8 and later versions.

Fraser GordonFull Access to the Clipboard

Related Posts

Take a look at these posts

1 comment

Join the conversation
  • Richmond Mathewson - November 8, 2015 reply

    However, on Linux at least, while I can copy-paste from the scriptEditor into a simple text editor such as Leafpad or gedit, I am unable to copy-paste directly to an e-mail client or an office suite; which would suggest that there is something ‘odd’ with the way data copied from LiveCode ends up being handled by the OS.

Join the conversation

*