Tre anni più tardi, in tempi più civilizzati, abbiamo Swift. Puoi scrivere un breve script di Swift per estrarre esattamente ciò che ti serve dalla lavagna di OS X.
Inserire il seguente snippet 3 rapido in un nuovo file di testo. Ho chiamato il mio pbpaste.swift
:
import Cocoa
let type = NSPasteboardTypeHTML
if let string = NSPasteboard.general().string(forType:type) {
print(string)
}
else {
print("Could not find string data of type '\(type)' on the system pasteboard")
exit(1)
}
Poi, copiare alcune html, ed eseguire swift pbpaste.swift
dalla directory in cui si inserisce il file.
Yay, html! Uggh, OS X ha aggiunto una tonnellata di markup personalizzato (e un tag <meta>
?!) - ma hey, almeno non è un testo normale!
Note:
NSPasteboardTypeHTML
è una speciale globale che restituisce la stringa "public.html"
- Ovviamente questo è HTML specifica, in modo che vorreste probabilmente a uno:
- Nome esso
pbpaste-html.swift
, oppure
- Leggere il tipo desiderato dagli argomenti della riga di comando
È un po 'lento, perché viene interpretato al volo, non compilato ed eseguito. Compilazione mi dà un 10x speed-up:
xcrun -sdk macosx swiftc pbpaste.swift -o pbpaste-html
Poi basta chiamare ./pbpaste-html
invece di swift pbpaste.swift
.
Swift 2 versione:
import Cocoa
let type = NSPasteboardTypeHTML
if let string = NSPasteboard.generalPasteboard().stringForType(type) {
print(string)
}
else {
print("Could not find string data of type '\(type)' on the system pasteboard")
exit(1)
}