<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Vansh</title>
    <description>The latest articles on DEV Community by Vansh (@enigma007).</description>
    <link>https://dev.to/enigma007</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4014302%2F8d03d76d-3dc1-41d4-bbdb-70f5b36d01a5.gif</url>
      <title>DEV Community: Vansh</title>
      <link>https://dev.to/enigma007</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/enigma007"/>
    <language>en</language>
    <item>
      <title>Why macOS pbcopy is broken in 2026 (and how I fixed it)</title>
      <dc:creator>Vansh</dc:creator>
      <pubDate>Sat, 04 Jul 2026 02:25:28 +0000</pubDate>
      <link>https://dev.to/enigma007/why-macos-pbcopy-is-broken-in-2026-and-how-i-fixed-it-19a3</link>
      <guid>https://dev.to/enigma007/why-macos-pbcopy-is-broken-in-2026-and-how-i-fixed-it-19a3</guid>
      <description>&lt;p&gt;If you spend some time in the macOS terminal, you probably use &lt;code&gt;pbcopy&lt;/code&gt;. It's the native way to pipe terminal output directly to your clipboard. &lt;/p&gt;

&lt;p&gt;Butttt, &lt;code&gt;pbcopy&lt;/code&gt; is fundamentally broken for modern developer workflows. &lt;/p&gt;

&lt;p&gt;Have you ever piped a token to your clipboard (&lt;code&gt;echo "hunny-bunny-secret-society" | pbcopy&lt;/code&gt;) and it copies that new line character in the end and that annoyed you?&lt;/p&gt;

&lt;p&gt;Or have you ever piped fancy colored texts ( like log errors ), and pasted a crap of invisible ANSI color codes?&lt;/p&gt;

&lt;p&gt;I got so so annoyed by this, and built a replacement for it.&lt;/p&gt;

&lt;p&gt;3 FUNDAMENTAL PROBLEMS WITH &lt;code&gt;pbcopy&lt;/code&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;New line character copy&lt;/li&gt;
&lt;li&gt;ANSI color code copy&lt;/li&gt;
&lt;li&gt;MOST IMPORTANT: a bad name (pbcopy suckss) &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Meet &lt;strong&gt;&lt;a href="https://github.com/Vansh-j/CopyCopy" rel="noopener noreferrer"&gt;CopyCopy (&lt;code&gt;cpcp&lt;/code&gt; for short)&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What makes &lt;code&gt;cpcp&lt;/code&gt; better?
&lt;/h2&gt;

&lt;p&gt;I built &lt;code&gt;cpcp&lt;/code&gt; with a "Do What I Mean" philosophy.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. It cleans your text automatically
&lt;/h3&gt;

&lt;p&gt;By default, &lt;code&gt;cpcp&lt;/code&gt; strips trailing whitespaces, newlines, and ANSI escape codes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Old way: Pastes "password123\n"&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"password123"&lt;/span&gt; | pbcopy 

&lt;span class="c"&gt;# New way: Pastes exactly "password123"&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"password123"&lt;/span&gt; | cpcp

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;(Need the raw output? Just pass the &lt;code&gt;-r&lt;/code&gt; or &lt;code&gt;--raw&lt;/code&gt; flag).&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Smart File vs. Text Detection
&lt;/h3&gt;

&lt;p&gt;If you pass an argument to &lt;code&gt;pbcopy&lt;/code&gt;, it just copies the literal string. &lt;code&gt;cpcp&lt;/code&gt; checks if the string is a valid file path first.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Copies the text contents of the file&lt;/span&gt;
cpcp notes.txt

&lt;span class="c"&gt;# Copies the actual image asset to your clipboard&lt;/span&gt;
cpcp screenshot.png

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can run &lt;code&gt;cpcp never_gona_give_you_up.png&lt;/code&gt; and immediately hit &lt;code&gt;Cmd+V&lt;/code&gt; in Figma, Slack, or where ever you want .&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Human Feedback (but Script Safe)
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;pbcopy&lt;/code&gt; is dead silent. You never actually know if it worked until you paste.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;cpcp&lt;/code&gt; detects whether &lt;code&gt;stderr&lt;/code&gt; is connected to a human interactive terminal (TTY). If you're a human, it prints a subtle success message: &lt;code&gt;✔ Copied 42 characters&lt;/code&gt;. If you are piping it inside a bash script, it stays dead silent so it doesn't corrupt your logs.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Technical Challenge: The Sandbox Trap
&lt;/h2&gt;

&lt;p&gt;Building this in Swift surfaced a really interesting quirk about the macOS clipboard and modern app sandboxing.&lt;/p&gt;

&lt;p&gt;When I first built the image copy feature, I just wrote the file's URL to the &lt;code&gt;NSPasteboard&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="n"&gt;pb&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;writeObjects&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kt"&gt;NSURL&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This worked perfectly if I pasted into &lt;strong&gt;Finder&lt;/strong&gt; (it moved the file). But if I pasted into &lt;strong&gt;Slack or Google Chrome&lt;/strong&gt;, absolutely nothing happened.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why?&lt;/strong&gt; Because modern web browsers and chat apps run in strict security sandboxes. They are intentionally blocked from reading arbitrary local &lt;code&gt;file://&lt;/code&gt; paths off your clipboard. They expect raw image data (like &lt;code&gt;public.png&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Fix:&lt;/strong&gt; I had to utilize "Multiple Representations." A single item on the macOS clipboard can hold several formats at once. I used &lt;code&gt;NSWorkspace&lt;/code&gt; to dynamically detect the file type, and attached &lt;em&gt;both&lt;/em&gt; the file URL and the raw binary data to a custom &lt;code&gt;NSPasteboardItem&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;item&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;NSPasteboardItem&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="c1"&gt;// 1. For Finder (File Reference)&lt;/span&gt;
&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;absoluteString&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;forType&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;fileURL&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// 2. For Sandboxed Apps (Raw Asset Data)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;typeString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="kt"&gt;NSWorkspace&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;shared&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;type&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;ofFile&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
   &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;fileData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="kt"&gt;Data&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;contentsOf&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;pasteboardType&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;NSPasteboard&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;PasteboardType&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;typeString&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fileData&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;forType&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;pasteboardType&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;pb&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;writeObjects&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, Finder consumes the URL representation, and Slack consumes the raw data representation. Best of both worlds!&lt;/p&gt;




&lt;h2&gt;
  
  
  Try it out (and a quick favor! 🙏)
&lt;/h2&gt;

&lt;p&gt;You can install &lt;code&gt;cpcp&lt;/code&gt; right now via Homebrew:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;brew tap vansh-j/cpcp
brew trust vansh-j/cpcp
brew &lt;span class="nb"&gt;install &lt;/span&gt;cpcp

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;I have a goal:&lt;/strong&gt; I want to get &lt;code&gt;cpcp&lt;/code&gt; merged into the official &lt;code&gt;homebrew-core&lt;/code&gt; repository so nobody has to use those &lt;code&gt;tap&lt;/code&gt; or &lt;code&gt;trust&lt;/code&gt; commands ever again.&lt;/p&gt;

&lt;p&gt;However, Homebrew Core requires a repository to have &lt;strong&gt;at least 75 GitHub Stars ⭐&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If you find this utility useful, &lt;strong&gt;&lt;a href="https://github.com/Vansh-j/CopyCopy" rel="noopener noreferrer"&gt;I would massively appreciate a star on the GitHub repo ⭐&lt;/a&gt;&lt;/strong&gt; to help me hit that milestone!&lt;/p&gt;

&lt;p&gt;Let me know what you think, or if you have any feature requests, drop them in the comments!&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>opensource</category>
      <category>cli</category>
      <category>swift</category>
    </item>
  </channel>
</rss>
