Webkit/WebArchive and NSFileWrapper examples

Moderators: LCMark, LCfraser

Post Reply
trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 957
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Webkit/WebArchive and NSFileWrapper examples

Post by trevordevore » 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`:

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
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`:

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
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.

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
You will find the code in the Webkit and NSFileWrapper folders. Here is the repo link:

https://github.com/trevordevore/lc-macos-toolset/
Trevor DeVore
ScreenSteps - http://www.screensteps.com

Levure Application Framework: https://github.com/trevordevore/levure
LiveCode Resources for Developers: http://livecode.bluemangolearning.com

Post Reply

Return to “LiveCode Builder”