The AppleScript duplicate
command is supposed to return the copied objects.
And while apps using the original AE-based functions seem to do that, apps based on the Cocoa Scripting framework seem to never return anything but missing value.
It appears that the command handler of NSCloneCommand
is responsible for not returning the specifiers for the cloned objects.
I was attempting to fix this in my scriptable app by subclassing the command, collecting the cloned object specifiers and then returning them.
This works well if only one item is duplicated.
It also works if multiple items are cloned along with using the to
parameter with the command (as in duplicate every widget to end
): Then I can return a specifier of type NSRangeSpecifier
that designates the first and last of those cloned items.
However, if one uses the duplicate command on multiple items without the to
parameter, then the items get sorted into the array in a non-consecutive manner. For instance, if there are initially 2 "x" elements, with id 1 and 2, duplicate every x
will insert a copy of each element right after its original, so that we'll have them in this order: 1, 3, 2, 4.
Now, how would one return a specifier for this, i.e. a specifier for items 3 and 4?
There is no "list" specifier in the sub classes of NSScriptObjectSpecifier
, and I cannot return an NSArray for each individual NSScriptObjectSpecifier
either, it seems. And while NSAppleEventDescriptor
supports creation of lists, I cannot figure out how I'd convert the object specifiers into NSAppleEventDescriptors.
How can I solve this other than enforcing a consecutive order of the cloned objects (which would require me to re-implement the NSCloneCommand
's operation entirely, I'm afraid).
BTW, Mark Aldritt, author of Script Debugger, confirms the issue that duplicate
(also: move
, open
) do not return values as they're supposed to.