clipboard

Prev Next

Function Names

clipboard

Description

If called with one parameter passed, then the payload will be copied both as ANSI and UTF-8 text on the clipboard. If called without any parameters, then the contents from the clipboard will be pasted into the return value, which is always a string, even if copied numbers are recalled. The clipbaord works across the different applications in your system. You will be notified with a brief message if the clipboard is not accessible, which is the case if the utilities (in MacOS and LINUX) are not available.

Note: Non-text contents copied on the clipboard (e.g. files, images, graphic objects, audio) cannot be pasted back.

Call as: procedure

Restrictions

Indirect parameter passing is disabled.

OS differences

In LINUX systems, the command 'xclip' will be used. To install it, type 'sudo apt install xclip'.
In MACOS systems, the commands 'pbcopy' and 'pbpaste' will be used. These commands should be part of MacOS standard installation.
In Windows systems, internal C/C++ operating system calls are used.

Parameter count

0,1

Parameters

No.TypeDescription
Opt. 1
input
valid types Text to copy

The specified contents will be copied onto the clipboard. All non-string types, e.g. numerals, will be converted to strings.

Return value

TypeDescription
string Clipboard contents

The text contents on the clipboard will be returned.

Examples


    echo("Copy a text to the clipboard");
    clipboard("Copied text");
    echo("Paste the contents in a different application, e.g. an editor, Word, Excel, etc.");
    echo("You have 5 seconds to copy some other text.  Sleeping for 5 seconds ...");
    sleep(5);
    echo("Current contents on the clipboard: ", clipboard() );

Output

Copy a text to the clipboard
Paste the contents in a different application, e.g. an editor, Word, Excel, etc.
You have 5 seconds to copy some other text.  Sleeping for 5 seconds ...
Current contents on the clipboard: Copied text
Try it yourself: Open LIB_Function_clipboard.b4p in B4P_Examples.zip. Decompress before use.