Skip to content

Instantly share code, notes, and snippets.

@meain
Forked from vi/pbcopy_html.swift
Created January 10, 2025 03:19
Show Gist options
  • Save meain/07c4f5f2092593061bb57b3356527bc1 to your computer and use it in GitHub Desktop.
Save meain/07c4f5f2092593061bb57b3356527bc1 to your computer and use it in GitHub Desktop.
Command line tool, like `xclip -in -t text/html` for Mac. For preparing content for Google Docs/Sheets.
#!/usr/bin/env swift
// Based on https://github.com/chbrown/macos-pasteboard/issues/8#issuecomment-906537204
import Cocoa
import Foundation
let pasteboard: NSPasteboard = .general
let dataTypeName : String = "public.html"
let dataType = NSPasteboard.PasteboardType(rawValue: dataTypeName)
var text : String = ""
while let line = readLine() {
text += line
text += "\n"
}
let data = text.data(using: .utf8)!
pasteboard.clearContents()
pasteboard.setData(data, forType: dataType)
exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment