'move' method removes replicants of target item

Hello,

I uses move method for moving some record to another folder. It works fine. But when I have some replicants of target item, ‘move’ method sucessfully move my record and remove all of it’s replicants. I want to move some record by script and preserve it’s replicants.

Is there any solution for this problem?

Thank you.

If you are moving records between databases, replicants will not be preserved.
Replicants are instances of the same file in the same database. Cross-database replicants are not possible.

I recall there was a reason for this, but I don’t recall the reason.

If I have a set of groups "a’, “b”, “c”. Make a text record in “a”. Replicate it to “b” and “c”. Then select the record in “a” and run this script:


tell application id "DNtp"
	set theRecord to the content record
	set theLocation to create location "Target"
	set theResult to move record theRecord to theLocation
end tell

The record from “a” is moved to “Target” and the replicants in “b” and “c” disappear.

I’d suggest you try this yourself Jim and let us know how that goes.

Indeed.
It does happen when walking the selection too.
It doesn’t happen with a manual drag and drop to the Target folder.

korm,

I executed your script, then exactly it happen. ‘a’ is moved to ‘Target’ directory and “b” and “c” disapper.

BLUEFROG,

Sadly it happen even between same database. Using drag and drop for moving works as expected, but ‘move’ method doesn’t.

@mishana: Yep. I also confirmed it. I will let Development know it is (at least) unexpected behavior.

You have to specify the “from” parameter if you want to move only the replicant located in a certain group.

Alright. This works:

tell application id "DNtp"
	set theRecord to the content record
	set theFrom to create location "a"
	set theTo to create location "d"
	set theResult to move record theRecord from theFrom to theTo
end tell

There is probably a cleaner way to define the “from” and “to” locations though.

The dictionary has

So, that takes a bit of thought. Maybe


Move all instances of a record to a different group.  Specify the "from" group to to move a single instance to a different group.

Thanks, changed.

Thank you!

Is there a better way to specify “from” and “to” than what I did in my last snippet above?

Depends on the actual task, e.g. recursive functions usually know the parent group. Sometimes the parents relationship (e.g. parent 1 of theRecord) might be useful too.

Thank korm, cgrunenberg! It works as expected.

OK

Here’s a cleaner version that moves the record from its parent group, to a group selected at the time the script is run. This version also works to move groups (and their replicants, if any). The moves are limited to the current database, although instructions in the script code explain how to remove this limitation.


(* Script to move a record from one group to another while
preserving any existing replicants of the reccord

korm v1 20160709
*)

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application id "DNtp"
	try
		set theRecord to the (first item of (the selection as list))
		set theFrom to the first parent of theRecord
		-- to move between databases,
		-- remove the following line and replace with "set theTo to display group selector"
		set theTo to display group selector for the current database
		set theResult to move record theRecord from theFrom to theTo
		
	on error
		display alert "We've had a problem.  Check your selection and try again."
	end try
	
end tell

May I ask about “The dictionary” here?

  • what dictionary is this? Is it an “application” dictionary?
    I ask because interested in scripting, but most of all interested in ‘how to best gather information and snippets’ of scripting.
    Adding it to an application dictionary seems interesting.

Every scriptable application in macOS has a “dictionary” that is accessed by Script Editor (an app provided by Apple) or whatever other application is being used to write and compile that script. I use Script Debugger, Script Editor is freely available for all macOS users (in older versions of the OS it was called AppleScript Editor), the Xcode development environment also uses the dictionary, and so on. The dictionary for any scriptable application is written and maintained by the developer of that application. It is a text file (usually with an .sdef extension) that resides inside the application package along with other resources that the application uses. It doesn’t matter where the dictionary lives, because Script Editor, etc., knows about it and will give you access to it.

Run Script Editor. Choose File > Open Dictionary. A list of scriptable applications is presented to you. Scroll down to DEVONthink Pro Office.app or whatever other app you’re interest in, select the app, and press Choose. The dictionary opens. It contains information about the scriptable commands, classes and properties, enumerations, and data types that that app supports in scripts. For example, the DEVONthink Pro Office dictionary entry for the “move” command (i.e., a verb) is shown below. (This is the updated version mentioned above for v2.9.) Not to go into it here, but there are lots of resources available for learning AppleScript – Frederiko recently posted some links here, I believe, if you look for their posting on the topic of scripting.

The dictionary is an aid – it doesn’t do anything other than explain how to do things in your script for that application.