Skip to content

Instantly share code, notes, and snippets.

@vi
Created June 24, 2023 23:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vi/ae5d1fe32ebcff0b618f931aee9a6067 to your computer and use it in GitHub Desktop.
Save vi/ae5d1fe32ebcff0b618f931aee9a6067 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