Created
February 25, 2019 06:18
-
-
Save fallroot/b6ddd7dd12ab0037e46bdd3dcae06f21 to your computer and use it in GitHub Desktop.
Simple Clipboard Viewer in macOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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: "Apple SD Gothic Neo"; 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