I copied my password to the clipboard! Can you delete it?

99

18

Following the best security practices, I keep a plain text file with my passwords on my hard drive. In fact, I just copied and pasted one of them to access my PPCG account.

In a lucid moment, I decide that the password should better not remain in the clipboard after its use. Since this happens to me often, I could use a program to remove the clipboard contents.

Challenge

Write a program or function that deletes or overwrites any text contained in the clipboard, using a programming language of your choice.

Additional details:

  • If your system has several clipboards, you can write the program for any one of them. The only requirement is that it must be possible for the user to copy and paste text using that clipboard.

  • If your clipboard keeps a history of recent copied entries, assume the most recent entry.

  • If your answer is specific to an operating system or clipboard, indicate it in the title of your post, together with the used language.

  • The clipboard is guaranteed to contain text when your program is run. You can either delete the contents from the clipboard, or overwrite it with something else (not necessarily text). The only requirement is that after running the program, pasting from the clipboard will not produce the original text.

  • If you choose to overwrite with some fixed or randomly chosen text, you can assume that the previous clipboard contents are different from that text, so the password is effectively removed. In other words, disregard the possibility that the filler text coincides with the password.

  • The program should not have any side-effects like restarting the system, closing programs, shutting down the computer, or freezing it. After your program is run, the user should be able to keep using the computer as normal, only with the password removed from the clipboard. Also, standard loopholes are forbidden.

Shortest code in bytes wins.

Luis Mendo

Posted 2017-02-26T18:36:01.387

Reputation: 87 464

What if the clipboard has an undetermined number of entries? – LarsW – 2017-02-26T19:27:34.713

@LarsW Can you please ellaborate or give an example? – Luis Mendo – 2017-02-26T19:43:17.143

Well, on my computer I can access the last ~10 I copied/selected, but I can imagine that number being different on different systems. I don't know if this matters at all, so that's why I asked. – LarsW – 2017-02-26T20:00:06.203

@LarsW Oh, I see. You can assume the most recent entry. Edited into the text – Luis Mendo – 2017-02-26T20:10:18.197

21

On a more serious note: Use something like keepass to do that for you.

– flawr – 2017-02-26T21:14:09.003

17"Disregard the possibility that the filler text coincides with the password." Solution: , 0 bytes. Overwrites the password with itself. – Esolanging Fruit – 2017-02-27T03:10:09.417

2@Challenger5 but that's only If you choose to overwrite with some fixed or randomly chosen text – Luis Mendo – 2017-02-27T10:08:08.780

11The very worst part about this question is that I can completely relate to the intro story despite knowing that it's satirical. ...so, keepass, huh? Should look into that... – Nat – 2017-02-27T11:01:41.857

@Challenger5 That wouldn't be a full Java program or function ;) – user41805 – 2017-02-28T10:22:10.823

Or you could...you know...copy something else?! Erase the last thing copied??!! Ha. Ha. Ha. – PlanetAstro_William – 2017-03-03T04:38:14.910

Answers

19

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.

Adám

Posted 2017-02-26T18:36:01.387

Reputation: 37 779

2

Isn't this 2 keystrokes? "A keystroke is a single press of a key on a keyboard. Each key press is a keystroke." http://www.computerhope.com/jargon/k/keystroke.htm

– Martijn – 2017-03-02T11:18:52.163

@Martijn Possibly. I just copied from here.

– Adám – 2017-03-02T11:20:37.360

I'm not sure it's really valid to score by keystrokes. Also, since you say As opposed to the other joking entries, I interpret that as you admitting this is not an actually valid answer. So I won't accept it even if it's the shortest one. If you can point me to some relevant meta-post establishing the validity of keystrokes as scoring method, I will happily accept this submission – Luis Mendo – 2017-04-21T22:54:22.017

@LuisMendo Your in-between-lines analysis is correct, but now that I actually took the time ro research on Meta: https://codegolf.meta.stackexchange.com/a/4817/43319 would seem to indicate that it is acceptable, as opposed to "Windows" which isn't an editor.

– Adám – 2017-04-23T04:09:15.727

@Adám My understanding it that that meta-post refers to a hypothetical "editor golf" challenge category, not to using the number of keystrokes as a scoring method for "code golf" challenges. I've pinged Doorknob and Dennis to know their opinion – Luis Mendo – 2017-04-23T15:34:52.300

I'm still not totally convinced that keystrokes are a valid scoring method and are comparable to bytes. But I haven't had any conclusive feedback to settle this, so I'm assuming it is valid and therefore accepting this answer – Luis Mendo – 2017-04-25T21:44:38.727

125

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.

Ben N

Posted 2017-02-26T18:36:01.387

Reputation: 1 623

24The shortest answer which actually clears the clipboard instead of setting it to a newline or something not-quite-blank. – Luna – 2017-02-27T18:57:08.857

1This is very nice. – beppe9000 – 2017-03-03T20:28:56.713

75

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.

user41805

Posted 2017-02-26T18:36:01.387

Reputation: 16 320

6Aaargh, I was just going to post this answer! +1, right tool for the job. :) – James – 2017-02-26T19:14:36.467

If there are more installations of vim than of powershell, this should be the accepted answer on the basis of "Universality" ;) – JPCF – 2017-03-01T13:26:43.370

1@JPCF and there are many more 'actual' applications written in C# than there are coffeescript etc. It doesn't make one better than the other when it comes to code-golf – Baldrickk – 2017-03-01T15:14:28.610

1I doubt there are more installations of vim than PowerShell, since it's installed by default in Windows 8 and up. – Robert Fraser – 2017-03-15T01:43:38.340

59

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.

SuperJedi224

Posted 2017-02-26T18:36:01.387

Reputation: 11 342

3Huh, I didn't know JS had this function. Works in Firefox too. (The contents of the clipboard become [\n ""\n]) – ETHproductions – 2017-02-26T19:17:19.877

1Can confirm this as well on Chrome. The clipboard changes to: [\n ""\n ] – haykam – 2017-02-26T20:10:09.747

33@ETHproductions Actually, this function doesn't really exist in JS. This is a console built-in. (Which doesn't invalidate the answer. But maybe it should be explained more explicitly.) – Arnauld – 2017-02-26T21:50:18.453

Well doesn't it exist through Document.execCommand("copy") or is that an internal-to-browser clipboard? I use that in some tamper monkey scripts, but too lazy to check it – pinkfloydx33 – 2017-03-01T09:32:52.063

1Okay... this is now my new most upvoted answer – SuperJedi224 – 2017-03-02T02:45:47.483

57

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 ;)

Laurel

Posted 2017-02-26T18:36:01.387

Reputation: 975

33

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)

Divcy

Posted 2017-02-26T18:36:01.387

Reputation: 501

2You could use sc instead of fc to avoid the error message. Then, the sc help text would be set on the clipboard. Also, +1 for telling me about clip. – Neil – 2017-02-26T21:54:40.110

2My one used cd. :-) – Hand-E-Food – 2017-02-26T21:55:32.797

I guessing clip won't pick up the output of a non-command? So you couldn't just run x|clip? – djsmiley2k TMW – 2017-02-26T22:27:02.410

@djsmiley2k Yes, it will pick up only the output from a valid command. – Divcy – 2017-02-26T22:42:19.737

The reason why sc and cd output is passed to the clipboard but fc won't is because sc and cd write its output to stdout but fc write its output to stderr (clip pick up an input from stdout but fc does not write anything to stdout) – Divcy – 2017-02-26T23:32:18.147

4You can knock another character off this. h is an alias (by default) for get-history, so you can do h|clip – Matthew Steeples – 2017-02-26T23:33:13.070

Try to post 1 language per answer, so you should probably delete either the batch or powershell code. – Rɪᴋᴇʀ – 2017-02-27T00:09:41.183

@Riker just edited, thank for a suggestion – Divcy – 2017-02-27T00:18:27.283

@Divcy feel free to post it as a separate answer! – Rɪᴋᴇʀ – 2017-02-27T00:20:39.723

@CPoll for later reference: Please don't make edits that add new code. Feel free to comment, but don't make edits. – Rɪᴋᴇʀ – 2017-03-01T18:31:55.390

@Divcy I saw that you approved the edit, please don't do that in the future (even though it's your post). If you look, DJ rejected it also. – Rɪᴋᴇʀ – 2017-03-01T18:32:22.597

32

Bash on macOS, 8 bytes

:|pbcopy

: could be replaced with almost any other single character.

ovs

Posted 2017-02-26T18:36:01.387

Reputation: 21 408

6:|pbcopy works in bash as well as zsh. – Digital Trauma – 2017-02-27T19:08:52.387

29

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.

Neil

Posted 2017-02-26T18:36:01.387

Reputation: 95 035

25Since it's C, can't you use 0 instead of NULL? – Orion – 2017-02-27T01:09:48.743

You can strip the #include I think – Krzysztof Szewczyk – 2019-12-13T20:44:44.057

Can you stick the OpenClipboard(0) inside the parens after EmptyClipboard? – ceilingcat – 2019-12-14T04:18:18.863

24

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.

Gurupad Mamadapur

Posted 2017-02-26T18:36:01.387

Reputation: 1 791

22

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();
  }
}

user18932

Posted 2017-02-26T18:36:01.387

Reputation:

2Could you use an empty string instead of null? Saves 2 bytes – Poke – 2017-02-27T00:58:18.743

1@Poke yes, that works. I was focusing on "deleting" the contents of the clipboard, as in truly clearing them out. Turns out overwriting is fine too. – None – 2017-02-27T01:34:15.247

17

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

pajonk

Posted 2017-02-26T18:36:01.387

Reputation: 2 480

1Nice! You can save a byte with [a1].Cut – Slai – 2017-03-06T18:18:20.037

17

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!)

snail_

Posted 2017-02-26T18:36:01.387

Reputation: 1 982

Thanks for the explanation, since that looks like two '! – msanford – 2017-03-02T23:03:26.170

16

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

8 bytes saved thanks to @wheatwizard.

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

hubacub

Posted 2017-02-26T18:36:01.387

Reputation: 161

1Welcome to the site! I notice a few golfs you can do. instead of importing system from os you can import os as o and call o.system instead. You also don't need the spaces around your pipe in the bash command. – Post Rock Garf Hunter – 2017-02-26T23:46:58.197

1Sidenote, to make this work on OSX you can use pbcopy instead of xclip – Post Rock Garf Hunter – 2017-02-26T23:47:40.290

print("") is also the same as print() – Post Rock Garf Hunter – 2017-02-26T23:49:08.120

@WheatWizard Thanks, edited. – hubacub – 2017-02-26T23:54:18.290

You can add 4 spaces to the beginning of each line to make it code formatting. I also think you don't need the space after the echo (works on my system without it). – Post Rock Garf Hunter – 2017-02-26T23:56:42.863

35It's 6 bytes shorter without the as o part... (import os \n os.system("echo |xclip") – Rɪᴋᴇʀ – 2017-02-27T00:02:44.900

4You can also replace echo with : for ":|xclip" – Rɪᴋᴇʀ – 2017-02-27T00:04:59.403

22Or just one line at 37 bytes: __import__('os').system("echo|xclip") – Daniel – 2017-02-27T00:23:42.750

FYI, this only works for the middle-click paste, not Ctrl-V. (I don't think that's disallowed though) – 2xsaiko – 2017-02-27T10:28:27.970

1@Dopapp Still not as short as Riker's suggestion. – mbomb007 – 2017-02-27T15:12:35.803

4There's also an alternative to xclip called xsel on Linux systems, which would save you another byte - and as already mentioned, remove the "as o" import part again, it just makes things longer: import os;os.system(":|xsel") (29 bytes). – Byte Commander – 2017-03-01T16:01:36.227

1@Riker, Of course, you could also use :|xclip -- foregoing Python altogether – jpaugh – 2017-03-01T21:55:54.297

@jpaugh that's already been done multiple times though... – Rɪᴋᴇʀ – 2017-03-01T21:57:43.043

1Don't edit other people's code. If you have any suggestions leave them in the comments. – fəˈnɛtɪk – 2017-03-03T23:20:36.337

14

Google Chrome Language, 2 keystrokes

<c-S><c-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)

zeppelin

Posted 2017-02-26T18:36:01.387

Reputation: 7 884

1Gah, I wanted to use Google Chrome, but I didn't realize that I could argue it as a superset of JS... well played. – Pavel – 2017-02-28T22:05:30.570

8Then I guess pressing the Print Screen button (1 keystroke) is a solution in Windows Language, which is a superset of Google Chrome Lang. – Memet Olsen – 2017-03-01T16:25:46.303

@MemetOlsen Yep, exactly, feel free to post it. We already have "Notepad++ Language" and "Google Chrome Language", so "Windows Language" seem like the next logical step to take ! :) – zeppelin – 2017-03-01T16:51:23.007

1@MemetOlsen it isn't quite a superset of Google Chrome Lang, since Chrome is an external "library" you have to download. It is a superset of IE lang, which is a superset of JS. – Pavel – 2017-03-01T19:59:05.283

Thanks guys, I added my suggestion as my first answer on this SE site. – Memet Olsen – 2017-03-02T09:05:36.623

11

bash + xsel 8 7bytes

xsel -c

Explanation

-b: Works on clipboard selection

-c: clears the selection

Abel Tom

Posted 2017-02-26T18:36:01.387

Reputation: 1 150

1+1, but this is not coreutils – pacholik – 2017-02-27T09:31:30.457

@pacholik Yea you need to install the package, since I operated it on the terminal, I mentioned it as coreutils. – Abel Tom – 2017-02-27T09:49:36.677

1On Debian, xsel is in the xsel package, not part of coreutils. – Brian Minton – 2017-02-27T15:42:26.893

Since we're allowed to use any clipboard we want to, I think you can drop the b. – Dennis – 2017-02-27T18:15:03.857

@Digital Trauma Fair enough – Abel Tom – 2017-02-27T19:53:56.160

10

Mathematica, 17 bytes

CopyToClipboard@0

Sets clipboard to the number 0.

JungHwan Min

Posted 2017-02-26T18:36:01.387

Reputation: 13 290

10

R (Windows) 18

writeClipboard("")

Flounderer

Posted 2017-02-26T18:36:01.387

Reputation: 596

Do you know of a Linux equivalent? – None – 2017-02-27T05:11:27.600

I think something like readLines(file("clipboard", "r")) might work. Try looking in the R help docs under "Functions to Manipulate Connections". – Flounderer – 2017-02-27T09:36:23.003

8

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.

user41805

Posted 2017-02-26T18:36:01.387

Reputation: 16 320

How about ls|xclip? – seshoumara – 2017-02-26T19:20:49.413

@seshoumara Thanks! (and to think that I ls /usr/bin | grep "^.\{1,3\}$"'d to search for a shorter command :P) – user41805 – 2017-02-26T19:26:16.930

3Or w|xclip for one less. Dumps list of logged-in users to the clipboard. – Reinstate Monica - ζ-- – 2017-02-26T21:56:21.883

4Or :|xclip. Actually clears the clipboard. – isaacg – 2017-02-27T05:39:32.003

Thanks guys for the help, I used w|xclip since it was the only one that worked on macOS – user41805 – 2017-02-27T17:39:05.640

Why would : not work? It's a Bash built-in. – Dennis – 2017-02-27T19:31:39.853

@Dennis For some reason, it doesn't change the clipboard content for me – user41805 – 2017-02-27T19:33:47.820

1Huh, works on my machine. And since submissions may expect empty input, so would a bare xclip without any pipes. – Dennis – 2017-02-27T19:39:34.280

8

Matlab, 19 13 bytes

gcf;print -dm

Set clipboard contents to an empty figure.

EBH

Posted 2017-02-26T18:36:01.387

Reputation: 221

It's 21 UTF-8 bytes – CAD97 – 2017-02-26T19:17:58.370

@LuisMendo This is longer (23): axes;print -dmeta;close but also works... – EBH – 2017-02-26T20:04:26.283

@EBH That close can arguably be removed. By "side effects" I was thinking of things disappearing, not appearing. Also, print(gcf,'-dm') works – Luis Mendo – 2017-02-26T20:13:17.753

@LuisMendo Well, I didn't know that -dm is like -dmeta, and thought the program should work 'silently', without popping any window :) – EBH – 2017-02-26T20:17:18.060

@EBH Feel free to edit your code with the suggestions if you want. That's usual in PPCG. I just realized this is your first answer on this site :-) – Luis Mendo – 2017-02-26T20:47:45.937

2@LuisMendo indeed, it is my first. Now the suggestion is even shorter. – EBH – 2017-02-26T20:53:48.083

8

Applescript, 23 bytes

set the clipboard to ""

arodebaugh

Posted 2017-02-26T18:36:01.387

Reputation: 577

Ohhh Thanks @DigitalTrauma – arodebaugh – 2017-02-27T19:48:06.063

You could remove the quotation marks entirely, but It had been done already

– sagiksp – 2017-02-28T10:01:32.743

7

Python + tkinter, 43 bytes

Python 3:

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

Python 2:

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

Trelzevir

Posted 2017-02-26T18:36:01.387

Reputation: 987

is tkinter included in the python distro? – Cruncher – 2017-02-27T16:59:43.320

@Cruncher It is in my Python 3. – DLosc – 2017-02-27T18:19:40.797

@Cruncher Yes, it's part of the stdlib, even though I believe debian packages it in a separate package (python-tk) from the "core python". – Bakuriu – 2017-03-01T20:13:55.697

Take a look at Dopapp's comment for an even shorter way.

– jpaugh – 2017-03-01T22:07:56.543

@jpaugh If you are referring to changing the import style to __import__("tkinter")...., this is 1 byte longer in this case. – Trelzevir – 2017-03-02T18:28:01.327

Ok. Missed that, sorry! – jpaugh – 2017-03-03T14:41:32.203

you could save 2 bytes by removing () and having an unnamed function

– Felipe Nardi Batista – 2017-05-05T11:12:10.117

7

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());
    }
}

adrianmp

Posted 2017-02-26T18:36:01.387

Reputation: 1 592

1System.Windows.Clipboard – Nat – 2017-02-27T11:23:49.920

4Also, Clipboard.Clear() is already a function, so the lambda can be dropped. – Nat – 2017-02-27T11:30:07.393

1I won't bother adding an answer for LINQPad since this answer would just run in it. System.Windows.Clipboard.Clear(); But, lprun might be a more lightweight way to run this answer than VS or even VS Code. – JMD – 2017-02-27T23:52:14.270

@Nat When omitting .Forms, it didn't compile on Linux and I don't have a Windows machine at the moment. – adrianmp – 2017-02-28T07:48:42.797

2@adrianmp that class is only contained in PresentationCore.dll, a reference added by default on WPF type projects. I have no idea if that dll is included in Mono/.NET Core – BgrWorker – 2017-02-28T16:54:52.017

@BgrWorker That explains things. It's not available in my Linux install. – adrianmp – 2017-03-01T10:01:36.860

6

Haskell, 34 bytes

import System.Hclip
setClipboard""

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

nimi

Posted 2017-02-26T18:36:01.387

Reputation: 34 639

6

Notepad++, 3 Keystrokes

a<c-A><c-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.

Pavel

Posted 2017-02-26T18:36:01.387

Reputation: 8 585

consider regex to be a valid language References ? Apparently RegExp is not Turing complete by itself. – zeppelin – 2017-02-28T19:23:41.877

3@zeppelin It doesn't have to be Turing Complete to be a valid language. – Pavel – 2017-02-28T19:41:48.613

It doesn't have to be Turing Complete to be a valid language By that measure, we can claim almost anything to be a "language".

I.e. XML or HTML do have a syntax too (and even call themselves languages, unlike RegExp), nevertheless I don't think they are acceptable.

Can you provide an example of a pure-Regexp answer, which has been upvoted by the community ?

Moreover I believe Notepad++, does not really "support regexp" in sense that it can invoke it programmatically, and opening the UI "Search and Replace" box to type a RegExp there, is not a "program code" by any measure. – zeppelin – 2017-02-28T19:53:51.457

2

@zeppelin http://meta.codegolf.stackexchange.com/a/4817/60042 <-- relevant meta post. Keep in mind you can access search-and-replace in N++ with <c-H>, and use <tab> to navigate through the UI and interact with all the relevant fields. Also note that regex can determine primality of and add numbers. (Both in unary, which is the default numeric representation for regex)

– Pavel – 2017-02-28T20:02:56.557

the meta-post in question refers to the Vim and Emacs class editors, which are extremely programmable, not Notepad.

And yes, I've seen people use RegExp for primality testing on this site, but that's just a funny corner-case and not a real proof of RegExp being a language. So please provide a reference to any upvoted "pure-Regexp" answer, to prove your point. – zeppelin – 2017-02-28T20:25:19.083

But, even if you think RegExp is a valid language, that does not make Notepad++ a language too, just because you can you can access search-and-replace in N++ with <c-H>, and use <tab> to navigate through the UI and interact with all the relevant fields, as that's just an isolated piece of functionality, requiring the UI interaction to launch it.

This way I can claim my IDE desktop shortcut to be a "a desktop shortcut language", just because I can launch my IDE by clicking on it. – zeppelin – 2017-02-28T20:31:53.240

just to illustrate my point, if I were to post an answer: Windows 7, 10 keystrokes: Win+R, type "echo.|clip", <CR> would you upvote it ? (and yes, Windows does support regexp and has a built-in shell and lot's of other things, but does it make it a "Windows-7-language" ?). – zeppelin – 2017-02-28T20:43:34.257

@zeppelin I would not, because that yields "Windows cannot find 'echo.|clip'". But in the general case, I wouldn't upvote it, because you're just executing shell commands so it would be a lot shorter if you said your language was batch. But it would be valid. – Pavel – 2017-02-28T21:09:18.343

ok I think I can see your logic, and I've just beaten you by 1 keystroke with the [Google Chrome Language !] (http://codegolf.stackexchange.com/a/111731/61904)

– zeppelin – 2017-02-28T22:01:31.047

6

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

Dane

Posted 2017-02-26T18:36:01.387

Reputation: 291

This isn't a function or fill program, but rather a snippet. You'd need to make it a verb in order for it to be valid. you could do something like 'clipcopy 'wd@,] – Conor O'Brien – 2017-03-01T22:15:16.003

Which "this" are you referring to? Both chunks of code are executable .ijs files. – Dane – 2017-03-01T23:28:33.500

I might have simply misunderstood. Sorry 'bout that haha. Anyhow, you can remove the space in between wd and 'clipcopy'. – Conor O'Brien – 2017-03-01T23:32:30.997

Thanks! Shaved off a byte. I'm just so used to spaces to help me read J that I didn't think about it. – Dane – 2017-03-01T23:51:43.680

6

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".

Martin Meier

Posted 2017-02-26T18:36:01.387

Reputation: 61

Welcome to the site! – Luis Mendo – 2017-02-28T15:07:02.297

5

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);

TecBrat

Posted 2017-02-26T18:36:01.387

Reputation: 222

https://jsfiddle.net/kgvwjj3k/ – TecBrat – 2017-02-27T18:07:52.397

Tested in FF and Chrome – TecBrat – 2017-02-27T18:10:19.920

1Don't post it until you golf it. For now, you can delete your answer, edit it to golf it, and then un-delete your answer. – NoOneIsHere – 2017-02-27T18:10:30.313

@NoOneIsHere, Okay, I went ahead and golfed it. Here's the new fiddle.

– TecBrat – 2017-02-27T18:34:10.553

As my edit history shows, I'm not practiced at golfing. I originally forgot simple things like removing as much white space as possible. – TecBrat – 2017-02-27T18:49:51.157

1Instead of commenting, please edit the fiddle into your answer. Also, great job on golfing. I gave you a +1. (FYI, the language is technically HTML + JavaScript.) – NoOneIsHere – 2017-02-27T18:59:44.893

@NoOneIsHere I know, but it's JS that's doing the work. – TecBrat – 2017-02-27T19:03:30.450

Why can't clipboard be erased using js without user event such as clicking a button? Then one could copy something to clipboard and set a timer to wipe it. – philcolbourn – 2018-02-14T11:28:40.673

5

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 ;)

Xenotoad

Posted 2017-02-26T18:36:01.387

Reputation: 151

5

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

zeppelin

Posted 2017-02-26T18:36:01.387

Reputation: 7 884

5

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

Golden Ratio

Posted 2017-02-26T18:36:01.387

Reputation: 143

4

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

Ismael Miguel

Posted 2017-02-26T18:36:01.387

Reputation: 6 797

You don't need the opening <? tag since you can run the code without the <? tag in the command line with the -r switch. See more info here: http://meta.codegolf.stackexchange.com/questions/7098/is-the-php-opening-tag-mandatory-in-byte-count

– Kodos Johnson – 2017-02-27T06:02:42.840

@KodosJohnson I intentionally left the opening tag there. – Ismael Miguel – 2017-02-27T09:04:02.330

@KodosJohnson He would still have to add the bytes in the flags. – ckjbgames – 2017-03-01T17:50:35.510

@ckjbgames No I wouldn't. The flag is free. I didn't change the code because I intentionally left the opening tags. – Ismael Miguel – 2017-03-01T17:54:56.663

@IsmaelMiguel I have seen people add the interpreter/compiler flags to the byte count. – ckjbgames – 2017-03-01T20:13:59.223

@ckjbgames They must be adding other flags. Quoting the accepted answer: running programs via commands such as php -r "code here" is acceptable without penalty. – Ismael Miguel – 2017-03-01T21:57:11.780

@IsmaelMiguel Which accepted answer are you quoting? Just out of curiosity. – Kodos Johnson – 2017-03-02T17:53:12.933

@KodosJohnson http://meta.codegolf.stackexchange.com/a/7146/ <-- this answer.

– Ismael Miguel – 2017-03-02T21:11:13.697

@IsmaelMiguel Thanks, I was starting to be concerned that I should go back and add penalties to all my old answers. – Kodos Johnson – 2017-03-02T21:15:50.630

4

Ruby, 11 bytes (Windows)

`echo|clip`

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

Sculper

Posted 2017-02-26T18:36:01.387

Reputation: 191

3

VB.NET, 29 bytes

Sub F
Clipboard.Clear
End Sub

Saved 2 bytes thanks to @hvd

Oliver

Posted 2017-02-26T18:36:01.387

Reputation: 7 160

1Can you drop ()? – Qwertiy – 2017-02-26T20:40:09.653

2

Why? https://dotnetfiddle.net/nZNS1E

– Qwertiy – 2017-02-26T21:11:00.227

1Edit file outside of VS. You can also compile it from command line, but I think VS will compile it unchanged if it was saved from the other program. – Qwertiy – 2017-02-26T21:19:30.230

Error: comment chain does not make sense. Please insert information about deleted comment >> – CalculatorFeline – 2017-02-27T04:01:51.063

Parens are optional in vb.net when calling a function if there are no params. – mbomb007 – 2017-02-27T15:18:07.100

1For further golfing, you can drop (). :) They're equally optional in a sub or function definition. – hvd – 2017-02-28T18:35:18.163

3

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))

Carcigenicate

Posted 2017-02-26T18:36:01.387

Reputation: 3 295

3

APL (Dyalog APL) on Windows, 27 bytes

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

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

⎕WCWindow Create a

'Clipboard' object with the

('Text' '') ""

Adám

Posted 2017-02-26T18:36:01.387

Reputation: 37 779

3

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)

Winny

Posted 2017-02-26T18:36:01.387

Reputation: 1 120

3

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.

Radovan Garabík

Posted 2017-02-26T18:36:01.387

Reputation: 437

Yeah I would say it does. It is just supposed to clear it – Christopher – 2017-03-01T19:30:02.760

3

Julia - 13 bytes

clipboard("")

Tasos Papastylianou

Posted 2017-02-26T18:36:01.387

Reputation: 233

Hardly needing any explanation :-) – Luis Mendo – 2017-03-02T00:30:17.533

3

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.

Old Badman Grey

Posted 2017-02-26T18:36:01.387

Reputation: 233

Assuming /cygdrive/c/WINDOWS/system32 is on your $PATH, cd|clip also works. – David Conrad – 2017-03-04T00:08:15.217

2

AutoIt, 11 bytes

ClipPut("")

Fills the clipboard with an empty string.

rahnema1

Posted 2017-02-26T18:36:01.387

Reputation: 5 435

2

Ruby 25 bytes (MacOS)

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

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

Carl

Posted 2017-02-26T18:36:01.387

Reputation: 21

1This can be golfed down to 11 bytes: `:|pbcopy` – Synoli – 2017-02-27T21:19:45.073

2

Tcl, 15 bytes.

Not the shortest but the most readable:

clipboard clear

note: must be executed with wish instead of tclsh

slebetman

Posted 2017-02-26T18:36:01.387

Reputation: 629

I think you should remove the note and change title to Tcl/Tk – sergiol – 2017-06-23T07:47:16.690

2

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();
    }
}

codeflush.dev

Posted 2017-02-26T18:36:01.387

Reputation: 121

2

Red, 19 bytes

write-clipboard ""

writes a null string to the system clipboard

AngryShovel

Posted 2017-02-26T18:36:01.387

Reputation: 21

1

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);
    }
}

cookie

Posted 2017-02-26T18:36:01.387

Reputation: 271

In fact, exiting with an error is allowed by default

– Luis Mendo – 2017-03-14T13:20:55.377

1

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();

sergiol

Posted 2017-02-26T18:36:01.387

Reputation: 3 055

@Luis Mendo: shortened. – sergiol – 2017-05-22T09:28:18.860

1

AutoIt, 11 bytes

ClipPut("")

Pretty simple.

10 bytes

ClipPut(0)

Could save 1 byte by setting clipboard to "0"

Algirdas Butkus

Posted 2017-02-26T18:36:01.387

Reputation: 31