Webkit/WebArchive and NSFileWrapper examples
Posted: Fri Jan 11, 2019 4:28 pm
Yesterday I uploaded some LiveCode Builder examples that wrap Webkit/WebArchive and NSFileWrapper to my repo for LCB exploration on macOS. I was exploring how to place an HTML document and an RTFD document on the clipboard so that a user can paste text and images into apps like Pages or Word as well as Apple Mail.
The Webkit example has a function that takes a path to an HTML file on your computer (could be updated to take a URL as well) and returns data that can be placed on the clipboard using `the rawclipboardData`:
The NSFileWrapper example has a function that takes a path to a file and returns a serialized representation of that file that can then be placed on the clipboard using `the rawclipboardData`:
I have tested `GetSerializedRepresentationFromFile()` with RTFD files though it should work with other types of files as well. I just don't know which ones.
Using `the raw clipboardData` you can put both RTFD and the webarchive on the clipboard at the same time.
You will find the code in the Webkit and NSFileWrapper folders. Here is the repo link:
https://github.com/trevordevore/lc-macos-toolset/
The Webkit example has a function that takes a path to an HTML file on your computer (could be updated to take a URL as well) and returns data that can be placed on the clipboard using `the rawclipboardData`:
Code: Select all
put GetWebArchiveDataFromFile("/path/to/my_html.html") into tArchive
lock clipboard
set the rawClipboardData to empty
set the rawClipboardData["com.apple.webarchive"] to tArchive
unlock clipboard
Code: Select all
put GetSerializedRepresentationFromFile("/path/to/my_rtf_file.rtfd") into tSerializedData
lock clipboard
set the rawClipboardData to empty
set the rawClipboardData["com.apple.flat-rtfd"] to tSerializedData
unlock clipboard
Using `the raw clipboardData` you can put both RTFD and the webarchive on the clipboard at the same time.
Code: Select all
...
lock clipboard
set the rawClipboardData to empty
set the rawClipboardData["com.apple.webarchive"] to tArchive
set the rawClipboardData["com.apple.flat-rtfd"] to tSerializedData
unlock clipboard
https://github.com/trevordevore/lc-macos-toolset/