Read application specific clipboard item as text

Alright, I emailed the file to you.

OK, so my guess was close – it’s actually a property lists archived with NSKeyedUnarchiver. And unfortunately trying to unarchive it fails because it uses a custom class. You could theoretically reverse engineer it, but you’d need a lot of time and patience, and you’d have to do it in Objective-C – with no guarantees that you’d get something usable.

You could try making a record of it like this:

set {theDict, theError} to current application's NSPropertyListSerialization's propertyListWithData:theObj options:0 |format|:(missing value) |error|:(reference)
if theDict = missing value then
	error (theError's localizedDescription() as text)
end if
return theDict as record

but I’m not sure that gets you far.

Reading the unarchived version would be great, but I think I can make do with this for now.

I could probably stop using CopyLess altogether if I could write the FCPX data to the clipboard. Is that pretty much the opposite of reading the clipboard?

Sort of, yes.

I have one more quick question. Say I want to modify an item in the plist “ffpasteboardobject” then write that back to the master plist “com.apple.flexo.proFFPasteboardUTI”. I’m trying to do this like so:

set theData to current application's NSPropertyListSerialization's dataWithPropertyList:theDict format:{"NSPropertyListBinaryFormat_v1_0"} options:0 |error|:(reference)

but am getting this


What is type Q? Is what I’m trying even possible?

You’re trying to pass a string where an enum is required. Try:

set {theData, theError} to current application's NSPropertyListSerialization's dataWithPropertyList:theDict |format|:(current application's NSPropertyListBinaryFormat_v1_0) options:0 |error|:(reference)

I’m attempting to write the FCPX data back to the clipboard. But I’m stuck on setPropertyList:forType. Here’s what I have:

on writeClipboard:thePath
	set thePlist to current application's NSDictionary's dictionaryWithContentsOfFile:thePath
	set theObj to thePlist's objectForKey:"ffpasteboardobject"
	set {theDict, theError} to current application's NSPropertyListSerialization's propertyListWithData:theObj options:0 format:(missing value) |error|:(reference)
	if theDict = missing value then
		error (theError's localizedDescription() as text)
	end if
	set {theData, theError} to current application's NSPropertyListSerialization's dataWithPropertyList:theDict format:(current application's NSPropertyListBinaryFormat_v1_0) options:0 |error|:(reference)
	set newRecord to {ffpasteboardcopiedtypes:{pb_anchoredObject:{|count|:1}}} & {ffpasteboardobject:theData} & {kffmodelobjectIDs:{}}
	set OBJcDict to current application's NSDictionary's dictionaryWithDictionary:newRecord
	set newClipboardItem to current application's NSPasteboard's setPropertyList:OBJcDict forType:"com.apple.flexo.proFFPasteboardUTI"
	set theNSPasteboard to current application's NSPasteboard's generalPasteboard()
	theNSPasteboard's clearContents()
	theNSPasteboard's writeObjects:{newClipboardItem}
end writeClipboard:

It returns the error:

What am I missing?

You’re sending the message to the pasteboard class, not a pasteboard, and you’re trying two methods at once – -writeObjects is an alternative to -setPropertyList:forType:. Try changing to something like this:

    set theNSPasteboard to current application's NSPasteboard's generalPasteboard()
   theNSPasteboard's clearContents()
  theNSPasteboard's setPropertyList:OBJcDict forType:"com.apple.flexo.proFFPasteboardUTI"

Oh, I see. What I was trying to do was a bit like telling Finder to move the folder class instead of one particular folder.

Clearly I’m still working out the fundamentals of AppleScriptObjC.

I was able to finish the script for creating hotkeys for Final Cut Pro X using NSPasteboard and a number of other ObjC classes: http://macscripter.net/viewtopic.php?id=43895

Thanks for all the help!

The next step is creating an interface for it. I created a post relating to this problem here: http://macscripter.net/viewtopic.php?id=43871

Any ideas would be greatly appreciated.