96
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ What if the clipboard has an undetermined number of entries? \$\endgroup\$ – LarsW Feb 26 '17 at 19:27
  • 20
    \$\begingroup\$ On a more serious note: Use something like keepass to do that for you. \$\endgroup\$ – flawr Feb 26 '17 at 21:14
  • 16
    \$\begingroup\$ "Disregard the possibility that the filler text coincides with the password." Solution: ` `, 0 bytes. Overwrites the password with itself. \$\endgroup\$ – Esolanging Fruit Feb 27 '17 at 3:10
  • 1
    \$\begingroup\$ @Challenger5 but that's only If you choose to overwrite with some fixed or randomly chosen text \$\endgroup\$ – Luis Mendo Feb 27 '17 at 10:08
  • 11
    \$\begingroup\$ The 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... \$\endgroup\$ – Nat Feb 27 '17 at 11:01

46 Answers 46

14
\$\begingroup\$

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.

\$\endgroup\$
  • 2
    \$\begingroup\$ Isn't this 2 keystrokes? "A keystroke is a single press of a key on a keyboard. Each key press is a keystroke." computerhope.com/jargon/k/keystroke.htm \$\endgroup\$ – Martijn Mar 2 '17 at 11:18
  • \$\begingroup\$ @Martijn Possibly. I just copied from here. \$\endgroup\$ – Adám Mar 2 '17 at 11:20
  • \$\begingroup\$ 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 \$\endgroup\$ – Luis Mendo Apr 21 '17 at 22:54
  • \$\begingroup\$ @LuisMendo Your in-between-lines analysis is correct, but now that I actually took the time ro research on Meta: codegolf.meta.stackexchange.com/a/4817/43319 would seem to indicate that it is acceptable, as opposed to "Windows" which isn't an editor. \$\endgroup\$ – Adám Apr 23 '17 at 4:09
  • \$\begingroup\$ @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 \$\endgroup\$ – Luis Mendo Apr 23 '17 at 15:34
121
\$\begingroup\$

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.

\$\endgroup\$
  • 22
    \$\begingroup\$ The shortest answer which actually clears the clipboard instead of setting it to a newline or something not-quite-blank. \$\endgroup\$ – Luna Feb 27 '17 at 18:57
  • 1
    \$\begingroup\$ This is very nice. \$\endgroup\$ – beppe9000 Mar 3 '17 at 20:28
71
\$\begingroup\$

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.

\$\endgroup\$
  • 6
    \$\begingroup\$ Aaargh, I was just going to post this answer! +1, right tool for the job. :) \$\endgroup\$ – DJMcMayhem Feb 26 '17 at 19:14
  • \$\begingroup\$ If there are more installations of vim than of powershell, this should be the accepted answer on the basis of "Universality" ;) \$\endgroup\$ – JPCF Mar 1 '17 at 13:26
  • 1
    \$\begingroup\$ @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 \$\endgroup\$ – Baldrickk Mar 1 '17 at 15:14
  • 1
    \$\begingroup\$ I doubt there are more installations of vim than PowerShell, since it's installed by default in Windows 8 and up. \$\endgroup\$ – Robert Fraser Mar 15 '17 at 1:43
56
\$\begingroup\$

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.

\$\endgroup\$
  • 3
    \$\begingroup\$ Huh, I didn't know JS had this function. Works in Firefox too. (The contents of the clipboard become [\n ""\n]) \$\endgroup\$ – ETHproductions Feb 26 '17 at 19:17
  • 1
    \$\begingroup\$ Can confirm this as well on Chrome. The clipboard changes to: [\n ""\n ] \$\endgroup\$ – haykam Feb 26 '17 at 20:10
  • 32
    \$\begingroup\$ @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.) \$\endgroup\$ – Arnauld Feb 26 '17 at 21:50
  • \$\begingroup\$ 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 \$\endgroup\$ – pinkfloydx33 Mar 1 '17 at 9:32
  • 1
    \$\begingroup\$ Okay... this is now my new most upvoted answer \$\endgroup\$ – SuperJedi224 Mar 2 '17 at 2:45
54
\$\begingroup\$

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

\$\endgroup\$
32
\$\begingroup\$

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)

\$\endgroup\$
  • 2
    \$\begingroup\$ You 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. \$\endgroup\$ – Neil Feb 26 '17 at 21:54
  • 2
    \$\begingroup\$ My one used cd. :-) \$\endgroup\$ – Hand-E-Food Feb 26 '17 at 21:55
  • \$\begingroup\$ I guessing clip won't pick up the output of a non-command? So you couldn't just run x|clip? \$\endgroup\$ – djsmiley2k Feb 26 '17 at 22:27
  • \$\begingroup\$ @djsmiley2k Yes, it will pick up only the output from a valid command. \$\endgroup\$ – Divcy Feb 26 '17 at 22:42
  • 4
    \$\begingroup\$ You can knock another character off this. h is an alias (by default) for get-history, so you can do h|clip \$\endgroup\$ – Matthew Steeples Feb 26 '17 at 23:33
32
\$\begingroup\$

Bash on macOS, 8 bytes

:|pbcopy

: could be replaced with almost any other single character.

\$\endgroup\$
  • 6
    \$\begingroup\$ :|pbcopy works in bash as well as zsh. \$\endgroup\$ – Digital Trauma Feb 27 '17 at 19:08
  • \$\begingroup\$ @Nax it's Fixed now \$\endgroup\$ – cat Feb 28 '17 at 14:44
29
\$\begingroup\$

C (on Windows), 65 62 bytes

#include<windows.h>
main(){OpenClipboard(0);EmptyClipboard();}

Edit: Saved 3 bytes thanks to @Orion.

\$\endgroup\$
  • 24
    \$\begingroup\$ Since it's C, can't you use 0 instead of NULL? \$\endgroup\$ – Orion Feb 27 '17 at 1:09
23
\$\begingroup\$

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.

\$\endgroup\$
22
\$\begingroup\$

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();
  }
}
\$\endgroup\$
  • 2
    \$\begingroup\$ Could you use an empty string instead of null? Saves 2 bytes \$\endgroup\$ – Poke Feb 27 '17 at 0:58
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ – user18932 Feb 27 '17 at 1:34
17
\$\begingroup\$

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

\$\endgroup\$
  • \$\begingroup\$ Thanks for the explanation, since that looks like two '! \$\endgroup\$ – msanford Mar 2 '17 at 23:03
17
\$\begingroup\$

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

\$\endgroup\$
  • 1
    \$\begingroup\$ Nice! You can save a byte with [a1].Cut \$\endgroup\$ – Slai Mar 6 '17 at 18:18
16
\$\begingroup\$

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

8 bytes saved thanks to @wheatwizard.

import os as o
o.system("echo|xclip")
\$\endgroup\$
  • 1
    \$\begingroup\$ Welcome 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. \$\endgroup\$ – Sriotchilism O'Zaic Feb 26 '17 at 23:46
  • 34
    \$\begingroup\$ It's 6 bytes shorter without the as o part... (import os \n os.system("echo |xclip") \$\endgroup\$ – Rɪᴋᴇʀ Feb 27 '17 at 0:02
  • 4
    \$\begingroup\$ You can also replace echo with : for ":|xclip" \$\endgroup\$ – Rɪᴋᴇʀ Feb 27 '17 at 0:04
  • 22
    \$\begingroup\$ Or just one line at 37 bytes: __import__('os').system("echo|xclip") \$\endgroup\$ – Daniel Feb 27 '17 at 0:23
  • 4
    \$\begingroup\$ There'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). \$\endgroup\$ – Byte Commander Mar 1 '17 at 16:01
14
\$\begingroup\$

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)

\$\endgroup\$
  • \$\begingroup\$ Gah, I wanted to use Google Chrome, but I didn't realize that I could argue it as a superset of JS... well played. \$\endgroup\$ – Pavel Feb 28 '17 at 22:05
  • 8
    \$\begingroup\$ Then I guess pressing the Print Screen button (1 keystroke) is a solution in Windows Language, which is a superset of Google Chrome Lang. \$\endgroup\$ – Memet Olsen Mar 1 '17 at 16:25
  • \$\begingroup\$ @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 ! :) \$\endgroup\$ – zeppelin Mar 1 '17 at 16:51
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ – Pavel Mar 1 '17 at 19:59
  • \$\begingroup\$ Thanks guys, I added my suggestion as my first answer on this SE site. \$\endgroup\$ – Memet Olsen Mar 2 '17 at 9:05
11
\$\begingroup\$

bash + xsel 8 7bytes

xsel -c

Explanation

-b: Works on clipboard selection

-c: clears the selection

\$\endgroup\$
  • 1
    \$\begingroup\$ +1, but this is not coreutils \$\endgroup\$ – pacholik Feb 27 '17 at 9:31
  • \$\begingroup\$ @pacholik Yea you need to install the package, since I operated it on the terminal, I mentioned it as coreutils. \$\endgroup\$ – Abel Tom Feb 27 '17 at 9:49
  • 1
    \$\begingroup\$ On Debian, xsel is in the xsel package, not part of coreutils. \$\endgroup\$ – Brian Minton Feb 27 '17 at 15:42
  • \$\begingroup\$ Since we're allowed to use any clipboard we want to, I think you can drop the b. \$\endgroup\$ – Dennis Feb 27 '17 at 18:15
  • \$\begingroup\$ @Digital Trauma Fair enough \$\endgroup\$ – Abel Tom Feb 27 '17 at 19:53
10
\$\begingroup\$

Mathematica, 17 bytes

CopyToClipboard@0

Sets clipboard to the number 0.

\$\endgroup\$
10
\$\begingroup\$

R (Windows) 18

writeClipboard("")
\$\endgroup\$
  • \$\begingroup\$ Do you know of a Linux equivalent? \$\endgroup\$ – user66045 Feb 27 '17 at 5:11
  • \$\begingroup\$ I think something like readLines(file("clipboard", "r")) might work. Try looking in the R help docs under "Functions to Manipulate Connections". \$\endgroup\$ – Flounderer Feb 27 '17 at 9:36
8
\$\begingroup\$

Matlab, 19 13 bytes

gcf;print -dm

Set clipboard contents to an empty figure.

\$\endgroup\$
  • \$\begingroup\$ It's 21 UTF-8 bytes \$\endgroup\$ – CAD97 Feb 26 '17 at 19:17
  • \$\begingroup\$ @LuisMendo This is longer (23): axes;print -dmeta;close but also works... \$\endgroup\$ – EBH Feb 26 '17 at 20:04
  • \$\begingroup\$ @EBH That close can arguably be removed. By "side effects" I was thinking of things disappearing, not appearing. Also, print(gcf,'-dm') works \$\endgroup\$ – Luis Mendo Feb 26 '17 at 20:13
  • \$\begingroup\$ @LuisMendo Well, I didn't know that -dm is like -dmeta, and thought the program should work 'silently', without popping any window :) \$\endgroup\$ – EBH Feb 26 '17 at 20:17
  • 2
    \$\begingroup\$ @LuisMendo indeed, it is my first. Now the suggestion is even shorter. \$\endgroup\$ – EBH Feb 26 '17 at 20:53
8
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ How about ls|xclip? \$\endgroup\$ – seshoumara Feb 26 '17 at 19:20
  • \$\begingroup\$ @seshoumara Thanks! (and to think that I ls /usr/bin | grep "^.\{1,3\}$"'d to search for a shorter command :P) \$\endgroup\$ – Cows quack Feb 26 '17 at 19:26
  • 3
    \$\begingroup\$ Or w|xclip for one less. Dumps list of logged-in users to the clipboard. \$\endgroup\$ – hexafraction Feb 26 '17 at 21:56
  • 4
    \$\begingroup\$ Or :|xclip. Actually clears the clipboard. \$\endgroup\$ – isaacg Feb 27 '17 at 5:39
  • 1
    \$\begingroup\$ Huh, works on my machine. And since submissions may expect empty input, so would a bare xclip without any pipes. \$\endgroup\$ – Dennis Feb 27 '17 at 19:39
8
\$\begingroup\$

Applescript, 23 bytes

set the clipboard to ""
\$\endgroup\$
  • \$\begingroup\$ Ohhh Thanks @DigitalTrauma \$\endgroup\$ – arodebaugh Feb 27 '17 at 19:48
  • \$\begingroup\$ You could remove the quotation marks entirely, but It had been done already \$\endgroup\$ – sagiksp Feb 28 '17 at 10:01
7
\$\begingroup\$

Python + tkinter, 43 bytes

Python 3:

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

Python 2:

from Tkinter import*;Tk().clipboard_clear()
\$\endgroup\$
  • \$\begingroup\$ is tkinter included in the python distro? \$\endgroup\$ – Cruncher Feb 27 '17 at 16:59
  • \$\begingroup\$ @Cruncher It is in my Python 3. \$\endgroup\$ – DLosc Feb 27 '17 at 18:19
  • \$\begingroup\$ @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". \$\endgroup\$ – Bakuriu Mar 1 '17 at 20:13
  • \$\begingroup\$ Take a look at Dopapp's comment for an even shorter way. \$\endgroup\$ – jpaugh Mar 1 '17 at 22:07
  • \$\begingroup\$ @jpaugh If you are referring to changing the import style to __import__("tkinter")...., this is 1 byte longer in this case. \$\endgroup\$ – Trelzevir Mar 2 '17 at 18:28
7
\$\begingroup\$

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());
    }
}
\$\endgroup\$
  • 1
    \$\begingroup\$ System.Windows.Clipboard \$\endgroup\$ – Nat Feb 27 '17 at 11:23
  • 4
    \$\begingroup\$ Also, Clipboard.Clear() is already a function, so the lambda can be dropped. \$\endgroup\$ – Nat Feb 27 '17 at 11:30
  • 1
    \$\begingroup\$ I 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. \$\endgroup\$ – JMD Feb 27 '17 at 23:52
  • \$\begingroup\$ @Nat When omitting .Forms, it didn't compile on Linux and I don't have a Windows machine at the moment. \$\endgroup\$ – adrianmp Feb 28 '17 at 7:48
  • 2
    \$\begingroup\$ @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 \$\endgroup\$ – BgrWorker Feb 28 '17 at 16:54
6
\$\begingroup\$

Haskell, 34 bytes

import System.Hclip
setClipboard""

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

\$\endgroup\$
6
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ consider regex to be a valid language References ? Apparently RegExp is not Turing complete by itself. \$\endgroup\$ – zeppelin Feb 28 '17 at 19:23
  • 2
    \$\begingroup\$ @zeppelin It doesn't have to be Turing Complete to be a valid language. \$\endgroup\$ – Pavel Feb 28 '17 at 19:41
  • \$\begingroup\$ 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. \$\endgroup\$ – zeppelin Feb 28 '17 at 19:53
  • 1
    \$\begingroup\$ @zeppelin 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) \$\endgroup\$ – Pavel Feb 28 '17 at 20:02
  • \$\begingroup\$ 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. \$\endgroup\$ – zeppelin Feb 28 '17 at 20:25
6
\$\begingroup\$

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

\$\endgroup\$
  • \$\begingroup\$ Welcome to the site! \$\endgroup\$ – Luis Mendo Feb 28 '17 at 15:07
6
\$\begingroup\$

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
\$\endgroup\$
  • \$\begingroup\$ 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@,] \$\endgroup\$ – Conor O'Brien Mar 1 '17 at 22:15
  • \$\begingroup\$ Which "this" are you referring to? Both chunks of code are executable .ijs files. \$\endgroup\$ – Dane Mar 1 '17 at 23:28
  • \$\begingroup\$ I might have simply misunderstood. Sorry 'bout that haha. Anyhow, you can remove the space in between wd and 'clipcopy'. \$\endgroup\$ – Conor O'Brien Mar 1 '17 at 23:32
  • \$\begingroup\$ Thanks! Shaved off a byte. I'm just so used to spaces to help me read J that I didn't think about it. \$\endgroup\$ – Dane Mar 1 '17 at 23:51
5
\$\begingroup\$

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);
\$\endgroup\$
  • \$\begingroup\$ jsfiddle.net/kgvwjj3k \$\endgroup\$ – TecBrat Feb 27 '17 at 18:07
  • \$\begingroup\$ Tested in FF and Chrome \$\endgroup\$ – TecBrat Feb 27 '17 at 18:10
  • 1
    \$\begingroup\$ Don'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. \$\endgroup\$ – NoOneIsHere Feb 27 '17 at 18:10
  • \$\begingroup\$ @NoOneIsHere, Okay, I went ahead and golfed it. Here's the new fiddle. \$\endgroup\$ – TecBrat Feb 27 '17 at 18:34
  • 1
    \$\begingroup\$ Instead 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.) \$\endgroup\$ – NoOneIsHere Feb 27 '17 at 18:59
5
\$\begingroup\$

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

\$\endgroup\$
5
\$\begingroup\$

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
\$\endgroup\$
4
\$\begingroup\$

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

\$\endgroup\$
  • \$\begingroup\$ 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: meta.codegolf.stackexchange.com/questions/7098/… \$\endgroup\$ – Kodos Johnson Feb 27 '17 at 6:02
  • \$\begingroup\$ @KodosJohnson I intentionally left the opening tag there. \$\endgroup\$ – Ismael Miguel Feb 27 '17 at 9:04
  • \$\begingroup\$ @KodosJohnson He would still have to add the bytes in the flags. \$\endgroup\$ – ckjbgames Mar 1 '17 at 17:50
  • \$\begingroup\$ @ckjbgames No I wouldn't. The flag is free. I didn't change the code because I intentionally left the opening tags. \$\endgroup\$ – Ismael Miguel Mar 1 '17 at 17:54
  • \$\begingroup\$ @IsmaelMiguel I have seen people add the interpreter/compiler flags to the byte count. \$\endgroup\$ – ckjbgames Mar 1 '17 at 20:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.