g | x | w | all
Bytes Lang Time Link
008UiuaSBCS240922T111631ZEurope20
065Rust240922T094735Zbzr
006Arturo240922T110746Zchunes
050Swift 5.10 macOS240403T145900ZmacOSist
012AutoHotkey231124T004149ZATaco
026APL Dyalog APL on Windows170228T084934ZAdá
045HTML 50211222T165634Zbzr
003Windows PowerShell200522T203914Zbzr
128Rust Windows211225T063534ZEzhik
069HTML + JavaScript170227T180303ZTecBrat
003Notepad++170227T201541ZPavel
001Excel170302T090728ZAdá
038Factor211222T170309Zchunes
002Google Chrome Language170228T215908Zzeppelin
002Windows 10211222T160516Zbzr
041Perl 5 + Win32Clipboard200812T052947ZRazetime
029Julia200523T061930Zjling
019Red191214T133903ZAngrySho
041C on Windows170226T184226ZNeil
011AutoIt170825T231553ZAlgirdas
008Bash on macOS170226T185020Zovs
051MFC170522T091447Zsergiol
056Java170306T160206ZFelix
139Java170314T131900Zuser6333
008Excel VBA170226T204327Zpajonk
009Cow170303T114224ZGolden R
015Tcl170302T235416Zslebetma
010Cygwin bash170302T175447ZOld Badm
006Javascript Chrome DevTools Console170226T184551ZSuperJed
013Julia170302T000507ZTasos Pa
012J Windows170227T214355ZDane
106Linux shell text console170301T121022ZRadovan
030C#170227T084824Zadrianmp
007Batch Windows 7 and higher version170226T195917ZDivcy
005Tcl/Tk wish shell REPL170228T192813Zzeppelin
029VB.NET170226T200956ZOliver
011Ruby170228T185436ZSculper
061Racket170228T163659ZWinny
033Python170228T141757ZMartin M
061Java 8 JavaFX170227T233741ZXenotoad
nanbash + xsel 7bytes170226T185336ZAbel Tom
023Applescript170226T201557Zarodebau
007Bash170226T184121Zuser4180
043Python + tkinter170226T210304ZTrelzevi
025Ruby170227T145855ZCarl
117Clojure170226T212707ZCarcigen
nan170226T232053Zuser1893
003PowerShell170227T004508ZBen N
018R Windows170227T001653ZFlounder
040Python170226T233904Zhubacub
010SmileBASIC 3170226T222002Zsnail_
013Matlab170226T191633ZEBH
020AppleScript170226T201621ZLaurel
034Haskell170226T200854Znimi
011AutoIt170226T191834Zrahnema1
024PHP + PHP GTK 2.0170226T192203ZIsmael M
017Mathematica170226T184513ZJungHwan
010AHK170226T185511ZGurupad
003Vim170226T184536Zuser4180

UiuaSBCS, 8 bytes

°&clip""

Try it here!

Rust, 82 65 bytes

-7 bytes thanks to emanresu A

let f=||arboard::Clipboard::new().unwrap().set_text("").unwrap();

Arturo, 6 bytes

clip""

Swift 5.10 (macOS), 50 bytes

The AppKit framework (and, by extension, NSPasteboard) are macOS-only.

import AppKit
NSPasteboard.general.clearContents()

Yeah. Turns out NSPasteboard has a method dedicated for this purpose.

This uses less bytes than setString(_:forType:), even with closure tricks, since you have to set the data type beforehand. That's AppKit for you.

AutoHotkey, 12 bytes

A_Clipboard=

AutoHotkey allows direct reading and writing to the clibpoard via the A_Clipboard global, and allows writing an empty string to a variable with just =.

APL (Dyalog APL) on Windows, 27 26 bytes

⎕A⎕WC'Clipboard'('Text'⎕A)

⎕A using the name "ABC...Z",

⎕WCWindow Create a

'Clipboard' object with the

('Text'⎕A) "ABC...Z"


Alternative of same length, but empties the clipboard and doesn't leave behind a global clipboard object:

(⎕NEW⊂'Clipboard').Text←''

⎕NEW⊂'Clipboard' create a NEW clipboard object

().Text←'' and set its Text property to the empty string

HTML 50 45 bytes

<x onclick=navigator.clipboard.writeText`x`>x

Click on the rendered letter x to copy x to the clipboard.

Windows PowerShell, 3 bytes

scb

Set the clipboard (scb) to null.

Rust (Windows), 128 bytes

#[link(name="user32")]extern"C"{fn OpenClipboard(h:u8);fn EmptyClipboard();}fn main(){unsafe{OpenClipboard(0);EmptyClipboard()}}

Calls some Windows API functions improperly, doesn't even close the clipboard afterwards:

#[link(name = "user32")]
extern "C" {
    fn OpenClipboard(h: u8);
    fn EmptyClipboard();
}
fn main() {
    unsafe {
        OpenClipboard(0);
        EmptyClipboard();
    }
}

HTML + JavaScript, 175 148 139 135 69 Bytes

Golfed:

<input value="c"onclick="this.select();document.execCommand('copy')">

Fiddle

Ungolfed

Got help from SitePoint

HTML:

<input style="display: none;" id="Empty" value="x">
<input id="clipclear" type="button" value="Clear The Clipboard">

JS:

function clearclip(){
empty=document.getElementById("Empty");
empty.style.display="block";
empty.select();
        document.execCommand('copy');
empty.style.display="none";
}      
document.getElementById("clipclear").addEventListener("click", clearclip, false);

Notepad++, 3 Keystrokes

a Ctrl-A Ctrl-C

Inserts the letter a, selects it, copies it to the keyboard.

Notepad++ is a valid language, it supports regex and is therefore a superset of regex, and we consider regex to be a valid language.

Excel, 1 keystroke

Ctrl-C

Works because Excel, uniquely, always has a selection. Probably works in other spreadsheet applications too. As opposed to the other joking entries, Excel answers are actually somewhat frequent on PPCG.

Factor, 38 bytes

""clipboard get set-clipboard-contents

Google Chrome Language, 2 keystrokes

Ctrl-S Ctrl-C

Based on this Notepad++ answer.

Google Chrome supports Javascript (which in turn supports RegExp), so I hereby claim it to be a superset of Javascript and a language of its own.

How it works:

Ctrl+S will invoke the "Save Page" dialog with the "New Tab" text pre-selected, Ctrl+C will copy it into the clipboard, displacing the previous content.

Sidenote:

You can access the Javascript functionality in Chrome, via javascript: URLs and the Developer Tools console (invoked with Ctrl+Shift+J)

Windows 10, 2 keystrokes

Win + V Delete

Based on the excel answer, the Google Chrome answer, and the Notepad++ answer.

Opens Windows Clipboard (this must be enabled in settings) and deletes the current entry.

Perl 5 + Win32::Clipboard, 41 bytes

$CLIP=Win32::Clipboard();
$CLIP->Empty();

Try it online!

Julia 29 bytes

InteractiveUtils.clipboard(9)

Red, 19 bytes

write-clipboard ""

writes a null string to the system clipboard

C (on Windows), 65 62 42 41 bytes

main(){EmptyClipboard(OpenClipboard(0));}

Note that the Visual C++ command-line needs /link user32.lib but the IDE or other compilers may automatically include this. Also this won't work in Win16 because the calling convention is incorrect.

Edit: Saved 3 bytes thanks to @Orion. Saved 20 bytes thanks to @KrzysztofSzewczyk. Saved a further byte thanks to @ceilingcat.

AutoIt, 11 bytes

ClipPut("")

Pretty simple.

10 bytes

ClipPut(0)

Could save 1 byte by setting clipboard to "0"

Bash on macOS, 8 bytes

:|pbcopy

: could be replaced with almost any other single character.

MFC, 54 51

OpenClipboard(0);EmptyClipboard();CloseClipboard();

Perhaps the first MFC submission ever!


If inside a method of a CWnd derived class I can use CWnd::OpenClipboard() which implementation is

_AFXWIN_INLINE BOOL CWnd::OpenClipboard()
    { ASSERT(::IsWindow(m_hWnd)); return ::OpenClipboard(m_hWnd); }

and I don't have to supply a parameter to OpenClipboard. Then it becomes:

MFC, 50

OpenClipboard();EmptyClipboard();CloseClipboard();

Java, 56 Bytes

javafx.scene.input.Clipboard.getSystemClipboard()::clear

It can be used with an functional interface (for example java.lang.Runnable) just like

()->javafx.scene.input.Clipboard.getSystemClipboard().clear()

which was accepted as a function on page 1.

Full example:

public class Test
{
    public static void main(String... args)
    {
        Runnable test1 = () -> javafx.scene.input.Clipboard.getSystemClipboard().clear();
        Runnable test2 = javafx.scene.input.Clipboard.getSystemClipboard()::clear;

        // both are valid Runnable Objects on which you can call the run()-Method to clear the clipboard
        test1.run();
        test2.run();
    }
}

Java, 139 bytes

enum c{;static{java.awt.Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new java.awt.datatransfer.StringSelection(""),null);}}

No one said that the program can't crash at the end.

Ungolfed version:

enum c {;
    static {
        java.awt.Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new java.awt.datatransfer.StringSelection(""), null);
    }
}

Excel VBA, 9 8 bytes

[A1].Cut

Overwrites the clipboard with contents of A1 cell in active worksheet (empty by default but may be any string/expression of your choice - just make sure it's not your password!).

Utilises the Immediate Window.

One byte saved thanks to Slai

Cow, 9 bytes

OOOMMMOOO

Explanation:

OOO set current memory block to 0
MMM if the current memory block is 0, paste the clipboard and clear the clipboard.
OOO set it back to 0

Tcl, 15 bytes.

Not the shortest but the most readable:

clipboard clear

note: must be executed with wish instead of tclsh

Cygwin (bash), 10 bytes

w>/dev/cl*

In Linux everything is a file. Except the clipboard. That is part of a program. How impure! Thankfully when Windows became enlightened with true ttys and bash, it was not hindered by the ancient blotch X. On Windows you can use the clipboard as file, the way it was meant to be used. (Ignore that this is worse for golfing).

Needs the procps-np package for w. In other mintty terminals (git bash), ls could be used.

Javascript (Chrome DevTools Console), 6 bytes

copy``

Note that this is a feature of the console (which also works in the FF console) and is not part of the language standard.

Julia - 13 bytes

clipboard("")

J (Windows), 12 bytes

wd'clipcopy'

wd is J's standard library for Windows. wd 'clipcopy password' would put the text password into the clipboard. Specifying nothing wipes the clipboard.

If you want a program to put your plaintext password into your clipboard, you could use the following:

pass =. 'abc123'
wd 'clipcopy ' , pass

Linux shell (text console), 10 (or 6) bytes

gpm -k;gpm

gpm(8) is the daemon providing mouse control for the Linux text terminal (not X11). gpm -k tells the daemon to shut down, no further pasting will be possible.

It could be shortened to just

gpm -k

which shutdowns the daemon but does not restart it - but it cold be argued that this goes against the "user should be able to keep using the computer as normal" requirement.

C#, 30 bytes

Thanks to Nat, JMD and BgrWorker for their suggestions!

System.Windows.Clipboard.Clear

C# without WPF, 36 bytes

System.Windows.Forms.Clipboard.Clear

Built-in function which empties the clipboard.

Full program with test case:

using System;
using System.Windows.Forms;

class ClearClipboard
{
    static void Main()
    {
        Action f =
        ()=>System.Windows.Forms.Clipboard.Clear();

        // test case:
        Clipboard.SetText("SomePassword!");
        Console.WriteLine("In clipboard initially: " + Clipboard.GetText());
        f();
        Console.WriteLine("In clipboard now: " + Clipboard.GetText());
    }
}

Batch (Windows 7 and higher version), 7 bytes

fc|clip

Note: it will response error message like "FC:..." but it works.

"clip" is a command to copy the output of another program to clipboard (available since windows 7)

"fc" is a command to compare two or more files. in this case we not input any file. it will error, then "clip" will set clipboard to an empty string.

provided that you have a file "a" in your current directory (it can be empty), you can do one better:

clip<a

Edit: See @Matthew Steeples comment for the shorter version (but in powershell not a batch)

Tcl/Tk wish shell (REPL), 5 bytes

cli c

Wish shell (REPL) allows for the incomplete commands, as long as there is no ambiguity, the full command would be:

clipboard clear

VB.NET, 29 bytes

Sub F
Clipboard.Clear
End Sub

Saved 2 bytes thanks to @hvd

Ruby, 11 bytes (Windows)

`echo|clip`

Runs the windows clip command to replace clipboard contents with "ECHO is on."

Racket, 61 bytes

Clears the secondary X11 clipboard, or the usual clipboard on other systems.

#lang racket/gui
(send the-clipboard set-clipboard-string""0)

Python 33 bytes (Only works on Windows).

4 bytes saved from @hubacub version.

3 bytes switching to windows, using @Divcy solution

import os
os.system("fc|clip")

Just registered in stackexchange, so I don't have the reputation to just comment on @hubacub submition. There is no need to expend 5 bytes with " as o" in the import to save 1 byte to reduce "os.system" to "o.system".

Java 8 (JavaFX), 61 bytes

()->javafx.scene.input.Clipboard.getSystemClipboard().clear()

The JavaFX API for manipulating the clipboard is a little more terse than AWT's ;)

bash + xsel 8 7bytes

xsel -c

Explanation

-b: Works on clipboard selection

-c: clears the selection

Applescript, 23 bytes

set the clipboard to ""

Bash, 11 10 8 7 bytes

2 bytes saved thanks to @seshoumara for using ls instead of echo

Thanks to hexafraction, isaacg and Riker for suggesting several 7-byters

w|xclip

The clipboard is set to the result of w. This only works on X11 based systems. For example, on macOS, this clipboard can be accessed by using an X based application like XQuartz.


Old answer only for macOS (11 9 bytes):

ls|pbcopy

This sets the clipboard content to a newline.

Python + tkinter, 43 bytes

Python 3:

from tkinter import*;Tk().clipboard_clear()

Python 2:

from Tkinter import*;Tk().clipboard_clear()

Ruby 25 bytes (MacOS)

IO.popen("pbcopy","w"){}

Launches the MacOS/OS X pbcopy as a subprocess and clears the clipboard.

Clojure, 117 bytes

#(.setContents(.getSystemClipboard(java.awt.Toolkit/getDefaultToolkit))(java.awt.datatransfer.StringSelection."")nil)

Basically the Java answer. Gets the system clipboard, and sets it to an empty string.

AWT lets you do so many random things. It's so verbose though!

Unfortunately, trying to put an import in there adds about 30 bytes, so I need to fully qualify everything.

(defn clear-clipboard []
  (.setContents
      (.getSystemClipboard
        (java.awt.Toolkit/getDefaultToolkit))
      (java.awt.datatransfer.StringSelection. "")
      nil))

Java 8, 127 125 bytes

Golfed:

()->java.awt.Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new java.awt.datatransfer.StringSelection(""),null)

Ungolfed:

public class ICopiedMyPasswordToTheClipboardCanYouDeleteIt {

  public static void main(String[] args) {
    f(() -> java.awt.Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
      new java.awt.datatransfer.StringSelection(""), null));
  }

  private static void f(Runnable x) {
    x.run();
  }
}

PowerShell, 3 bytes

scb

That's a default alias for Set-Clipboard. When called with nothing piped in and no arguments supplied, it blows away the current clipboard contents.

R (Windows) 18

writeClipboard("")

Python 56 48 40 bytes (Only works on Linux).

8 bytes saved thanks to @wheatwizard.

import os as o
o.system("echo|xclip")

SmileBASIC 3, 10 bytes

Finally, a challenge practically made for SmileBASIC 3!

CLIPBOARD"

CLIPBOARD is a builtin that sets the environment's text clipboard to the given string. Here we give it an empty string (closing " isn't needed!)

Matlab, 19 13 bytes

gcf;print -dm

Set clipboard contents to an empty figure.

AppleScript, 20 bytes

set the clipboard to

Sets the clipboard to... nothing.


I saved a lot of bytes by removing the code to send me the contents of the clipboard ;)

Haskell, 34 bytes

import System.Hclip
setClipboard""

Just a boring library function. There's also clearClipboard for the same byte count.

AutoIt, 11 bytes

ClipPut("")

Fills the clipboard with an empty string.

PHP + PHP GTK 2.0, 24 bytes

This assumes you already have the PHP GTK extension loaded.

<?GtkClipboard::clear();

Documentation reference: http://gtk.php.net/manual/en/html/gtk/gtk.gtkclipboard.method.clear.html

Mathematica, 17 bytes

CopyToClipboard@0

Sets clipboard to the number 0.

AHK, 10 bytes (Windows)

clipboard=

Clears text content of the clipboard. If clipboardAll is used it clears everything.

From the docs -

Clipboard is a built-in variable that reflects the current contents of the Windows clipboard if those contents can be expressed as text. By contrast, ClipboardAll contains everything on the clipboard, such as pictures and formatting.

Vim, 3 bytes

"*Y

Sets the clipboard content to a newline.

By default, vim opens an empty buffer on start up. Now the program Yanks (copy) the entire line (including a newline) and store it in your clipboard by yanking it the text into register "*. The * can be changed to a + for the other clipboard.