| Bytes | Lang | Time | Link |
|---|---|---|---|
| 008 | UiuaSBCS | 240922T111631Z | Europe20 |
| 065 | Rust | 240922T094735Z | bzr |
| 006 | Arturo | 240922T110746Z | chunes |
| 050 | Swift 5.10 macOS | 240403T145900Z | macOSist |
| 012 | AutoHotkey | 231124T004149Z | ATaco |
| 026 | APL Dyalog APL on Windows | 170228T084934Z | Adá |
| 045 | HTML 50 | 211222T165634Z | bzr |
| 003 | Windows PowerShell | 200522T203914Z | bzr |
| 128 | Rust Windows | 211225T063534Z | Ezhik |
| 069 | HTML + JavaScript | 170227T180303Z | TecBrat |
| 003 | Notepad++ | 170227T201541Z | Pavel |
| 001 | Excel | 170302T090728Z | Adá |
| 038 | Factor | 211222T170309Z | chunes |
| 002 | Google Chrome Language | 170228T215908Z | zeppelin |
| 002 | Windows 10 | 211222T160516Z | bzr |
| 041 | Perl 5 + Win32Clipboard | 200812T052947Z | Razetime |
| 029 | Julia | 200523T061930Z | jling |
| 019 | Red | 191214T133903Z | AngrySho |
| 041 | C on Windows | 170226T184226Z | Neil |
| 011 | AutoIt | 170825T231553Z | Algirdas |
| 008 | Bash on macOS | 170226T185020Z | ovs |
| 051 | MFC | 170522T091447Z | sergiol |
| 056 | Java | 170306T160206Z | Felix |
| 139 | Java | 170314T131900Z | user6333 |
| 008 | Excel VBA | 170226T204327Z | pajonk |
| 009 | Cow | 170303T114224Z | Golden R |
| 015 | Tcl | 170302T235416Z | slebetma |
| 010 | Cygwin bash | 170302T175447Z | Old Badm |
| 006 | Javascript Chrome DevTools Console | 170226T184551Z | SuperJed |
| 013 | Julia | 170302T000507Z | Tasos Pa |
| 012 | J Windows | 170227T214355Z | Dane |
| 106 | Linux shell text console | 170301T121022Z | Radovan |
| 030 | C# | 170227T084824Z | adrianmp |
| 007 | Batch Windows 7 and higher version | 170226T195917Z | Divcy |
| 005 | Tcl/Tk wish shell REPL | 170228T192813Z | zeppelin |
| 029 | VB.NET | 170226T200956Z | Oliver |
| 011 | Ruby | 170228T185436Z | Sculper |
| 061 | Racket | 170228T163659Z | Winny |
| 033 | Python | 170228T141757Z | Martin M |
| 061 | Java 8 JavaFX | 170227T233741Z | Xenotoad |
| nan | bash + xsel 7bytes | 170226T185336Z | Abel Tom |
| 023 | Applescript | 170226T201557Z | arodebau |
| 007 | Bash | 170226T184121Z | user4180 |
| 043 | Python + tkinter | 170226T210304Z | Trelzevi |
| 025 | Ruby | 170227T145855Z | Carl |
| 117 | Clojure | 170226T212707Z | Carcigen |
| nan | 170226T232053Z | user1893 | |
| 003 | PowerShell | 170227T004508Z | Ben N |
| 018 | R Windows | 170227T001653Z | Flounder |
| 040 | Python | 170226T233904Z | hubacub |
| 010 | SmileBASIC 3 | 170226T222002Z | snail_ |
| 013 | Matlab | 170226T191633Z | EBH |
| 020 | AppleScript | 170226T201621Z | Laurel |
| 034 | Haskell | 170226T200854Z | nimi |
| 011 | AutoIt | 170226T191834Z | rahnema1 |
| 024 | PHP + PHP GTK 2.0 | 170226T192203Z | Ismael M |
| 017 | Mathematica | 170226T184513Z | JungHwan |
| 010 | AHK | 170226T185511Z | Gurupad |
| 003 | Vim | 170226T184536Z | user4180 |
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
AppKitframework (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",
⎕WC Window 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')">
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.
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.