• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Scriptable multi-clipboard utility?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scriptable multi-clipboard utility?


  • Subject: Re: Scriptable multi-clipboard utility?
  • From: Michael Grant <email@hidden>
  • Date: Sun, 09 Mar 2014 19:50:48 -0500

Thanks Shane, I'm the OP. Copying files is pretty much an extreme edge case, and offhand I can't think of any reason I'd deliberately use this script with files. I suppose it's conceivable that I might someday want to copy a group of files somewhere and also enter their names one-by-one into a form or something, but I'd have to rack my brains to come up with a scenario where I'd want to, and meanwhile it's not really worth pursuing. I was just asking in case someone has already dealt with this and had a solution at hand.

Michael



On Sun, Mar 9, 2014 at 7:39 PM, Shane Stanley <email@hidden> wrote:
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:

the clipboard as record

{«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

-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden



--
There's really no such thing as translating. It's all a scam. We basically just make stuff up and try to make it sound plausible.
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Scriptable multi-clipboard utility?
      • From: Shane Stanley <email@hidden>
References: 
 >Scriptable multi-clipboard utility? (From: Michael Grant <email@hidden>)
 >Re: Scriptable multi-clipboard utility? (From: Michael Grant <email@hidden>)
 >Re: Scriptable multi-clipboard utility? (From: "koenig.yvan" <email@hidden>)
 >Re: Scriptable multi-clipboard utility? (From: "koenig.yvan" <email@hidden>)
 >Re: Scriptable multi-clipboard utility? (From: Michael Grant <email@hidden>)
 >Re: Scriptable multi-clipboard utility? (From: "koenig.yvan" <email@hidden>)
 >Re: Scriptable multi-clipboard utility? (From: Michael Grant <email@hidden>)
 >Re: Scriptable multi-clipboard utility? (From: "koenig.yvan" <email@hidden>)
 >Re: Scriptable multi-clipboard utility? (From: Michael Grant <email@hidden>)
 >Re: Scriptable multi-clipboard utility? (From: "koenig.yvan" <email@hidden>)
 >Re: Scriptable multi-clipboard utility? (From: Michael Grant <email@hidden>)
 >Re: Scriptable multi-clipboard utility? (From: "koenig.yvan" <email@hidden>)
 >Re: Scriptable multi-clipboard utility? (From: Shane Stanley <email@hidden>)

  • Prev by Date: Re: Scriptable multi-clipboard utility?
  • Next by Date: Re: Scriptable multi-clipboard utility?
  • Previous by thread: Re: Scriptable multi-clipboard utility?
  • Next by thread: Re: Scriptable multi-clipboard utility?
  • Index(es):
    • Date
    • Thread