On 10 Mar 2014, at 9:11 am, koenig.yvan <email@hidden> wrote:
As you may see, the resetted contents is not the original one.
The components aren’t in the same order and an extraneous component is added.
The order doesn't matter in a record, and in most cases the extra entry probably doesn't either.
The real issue for the OP is this:
I also tried it with a group of copied files from the Finder, but when trying to paste them after running the script, only one file was fully restored for pasting in the Finder
If you copy several files and run "the clipboard as record", you will see the problem:
{«class furl»:file "Macintosh HD:Applications:Mail.app:", «class ut16»:"Mail.app Maps.app Messages.app", «class utf8»:"Mail.app Maps.app Messages.app", Unicode text:"Mail.app Maps.app Messages.app", string:"Mail.app Maps.app Messages.app"}
You can see the three filenames in the various string classes, but for «class furl», there is only one entry: the first of the files. So the problem is not in restoring the contents of the clipboard, as in getting it in the first place.
It used to be that there was only one item on the clipboard, but it can now hold more than one. So in this case the first item on the pasteboard contains one file, plus one string, one UTF8 string, etc. The other files are separate clipboard items. Unfortunately the AS clipboard command can only see the first clipboard item. I'm not optimistic about that but it may be the subject of a bug report.
The ability to get to all clipboard items from AS should be. The change to multiple clipboards was made in OS X 10.6.
Again, this could probably be worked around in ASObjC. For example, if the OP knows he's going to be working with file selections, he could use an ASObjC lib containing:
use framework "Foundation" use framework "AppKit"
on getFilesOnClip() set pb to current application's NSPasteboard's generalPasteboard() set theURLs to pb's readObjectsForClasses:{current application's NSURL's |class|()} options:(missing value) set theStrings to pb's readObjectsForClasses:{current application's NSString's |class|()} options:(missing value) set theURLs to theURLs's valueForKey:"filePathURL" -- convert from fileref URLs return {theURLs, theStrings} end getFilesOnClip
on setFilesOnClipTo:{theFiles, theStrings} set pb to current application's NSPasteboard's generalPasteboard() pb's clearContents() pb's writeObjects:theFiles if theStrings's |count|() as integer > 0 then pb's setString:(theStrings's objectAtIndex:0) forType:(current application's NSStrinPboardType) end if end setFilesOnClipTo:
Called by:
use theLib : script "<lib name>" use scripting additions
log (the clipboard as record) set theStuff to theLib's getFilesOnClip() -- store clip details set the clipboard to "xyz" -- do his stuff here theLib's setFilesOnClipTo:theStuff -- restore clip details the clipboard as record
The principle could be extended to other stuff on the clipboard if needed. The easiest way might be to use Yvan's code if there are no files, and mine if they are:
if length of (clipboard info for «class furl») is 0 then -- no files, so do Yvan way else -- contains file(s) so do ASObjC way end if |