First, the best way to examine the clipboard is to create a simple macOS application:
let pasteboard = NSPasteboard.general
for element in pasteboard.pasteboardItems! {
for type in element.types {
print(type)
if let string = element.string(forType: type)?.prefix(30) {
print(string)
} else {
let data = element.data(forType: type)
print(data)
}
}
}
After running this script, you'll notice that when you copy data from Google Sites, it places content in 3 formats:
- Text
public.html
com.apple.WebKit.custom-pasteboard-data
Overwriting the contents of the clipboard with a subset of these shows that although public.html
does paste something into Google Sites, the formatting is all off. Thus com.apple.WebKit.custom-pasteboard-data
is the one we actually care about.
You can't convert the contents directly to a string as it'll crash the app or show gibberish depending on which encoding you select. If we write its data contents into a file on disk, we can examine its contents via Hex Fiend. There you'll see why that is the case:

It appears that the text starts off as simple Ascii encoding and is eventually JSON encoded as UTF-16. Interestingly enough, the format seems to be application/x-vnd.google-sites-document
yet a Google search for this format doesn't yield any relevant results.
The next step is to go back to Google Sites, copy something with the word "Test" to the clipboard, and then use Hex Fiend to search for est
(00 65 00 73 00 74
) then try replacing the e
with E
, then copy that to the clipboard:
let url = URL(fileURLWithPath: "readdata")
let data = try! Data(contentsOf: url)
let pasteboardType = NSPasteboard.PasteboardType(rawValue: "com.apple.WebKit.custom-pasteboard-data")
let pasteboard = NSPasteboard.general
pasteboard.clearContents()
assert(pasteboard.setData(data, forType: pasteboardType))
assert(pasteboard.pasteboardItems![0].types.count == 1)
After running that code and pasting on Google Sites, it showed the word TEst
instead of Test
, proving that this is possible.
My exploration ended there because I needed the script to be run via a Google Apps Script running on a Google Spreadsheet. However, it's been historically difficult to copy text to the clipboard via Javascript, let alone needing to do that with a custom format (not just text), and via a Google Apps Script (rather than using the HTML DOM and the Clipboard API).
Had I continued down this path, I would do the following:
- In Google Sites, create a "template" of what I want to paste with dummy values (e.g.
Title goes here
, Subtitle goes here
, etc.).
- Replace those dummy values with the real values.
Deploy it on one of these platforms:
Since there is no easy to use API on Google Apps Scripting, you may find the maintenance cost of either of those solutions to be too much, and just hope that the new Google Sites gets App Scripting support.