CopyToClipboard
New to Analytica 6.5
CopyToClipboard( content, format, empty )
Puts «content» on the system clipboard, emptying any content that was previously there.
Parameters
- content
- The data to be placed on the clipboard. This will usually be either text, an image, or an in-memory binary data term.
- format
- (Optional) The name of a format to be posted. This can be a standard format name such as "text", "bitmap", or a custom format name such as "PNG", "HTML Format", etc. This is generally not needed when posting text or an image since it figures out the usual formats automatically. You will need it when posting binary data.
- empty
- (Optional) When omitted or True, it empties the previous content of the clipboard before posting. When False, it adds the format to the content already there. You can use
empty:False
to post multiple formats.
Example usage
Copying text to the clipboard
CopyToClipboard( "hello world" )
Copying an image to the clipboard
Local img := ReadImageFile( "", true ); CopyToClipboard( img )
If you were to select a PNG file, this would post both a "bitmap" format as well as a "PNG" format. On the other hand, if you post:
CopyToClipboard( img, "PNG" )
it would post only the "PNG" format without the "bitmap" format. Beware that it does not check that your image really is a PNG! "PNG" is not a standard format, but it is commonly used as a custom format, such that many applications recognize it.
Copying HTML format to clipboard
A HTML format can be useful when you want to include formatting. However, this is not a standard format. Gmail uses a custom format named "HTML Format", but it requires more that just HTML content. A header is required before the HTML as illustrated here:
Version:0.9 StartHTML:0000000100 EndHTML:0000000105 StartFragment:0000000099 EndFragment:0000000198 <!DOCTYPE html> <html> <body><!--StartFragment--> <h1>Example</h1> <p>This <i>illustrates</i> the <code>"HTML Format"</code> clipboard type used by gmail.</p> <!--EndFragment--></body> </html>
The StartHTML, EndHTML, StartFragment, and EndFragment offsets indicate the positions of the HTML content and the fragment within the clipboard data. The positions are represented by zero-padded 10-digit numbers. The StartFragment and EndFragment comments are also necessary.
Posting multiple formats
You can post data in multiple formats. It doesn't even have to be the same content. For example:
Local url := "https://analytica.com/wp-content/uploads/2023/07/logo.png"; Local logo := ReadFromURL( url ); CopyToClipboard( logo ); CopyToClipboard( url, format: "source_url", empty:False ); CopyToClipboard( "logo.png", format: "text", empty:False )
Enable comment auto-refresher