Skip to content

Instantly share code, notes, and snippets.

@fallroot
Created February 25, 2019 06:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fallroot/b6ddd7dd12ab0037e46bdd3dcae06f21 to your computer and use it in GitHub Desktop.
Save fallroot/b6ddd7dd12ab0037e46bdd3dcae06f21 to your computer and use it in GitHub Desktop.
Simple Clipboard Viewer in macOS
/*
* Simple Clipboard Viewer in macOS
* Run with Script Editor
*/
ObjC.import('AppKit')
function getPasteboardItemsAsString () {
const items = $.NSPasteboard.generalPasteboard.pasteboardItems
return [...Array(items.count).keys()].map(i => {
const item = items.objectAtIndex(i)
const types = ObjC.deepUnwrap(item.types)
const result = {}
types.forEach(type => {
result[type] = item.stringForType(type).js
})
return result
})
}
console.log(JSON.stringify(getPasteboardItemsAsString(), null, '\t'))
/*
[
{
"public.html": "<meta charset='utf-8'><h1 style=\"color: rgb(0, 0, 0); font-family: &quot;Apple SD Gothic Neo&quot;; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Hello, world!</h1>",
"public.utf8-plain-text": "Hello, world!"
}
]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment