stupid question about working with groups in scripts

Hello,

I’m trying to write a script that moves a record to its parent group, but I don’t seem to understand how to get this work without parsing the path of the group through string calls. This must be wrong, but I can’t figure out how to make it work.
If I run the following block of code, devon think pro just smiles at me…can anyone give me a hint?


tell application "DEVONthink Pro"
	set x to selection
	set z to first item of x
	set y to parent of z
	---so far so good, I think

--but this fails:
	move record (first item of x) to (first item of y)
	
end tell


thanks,

Eric

Okay, well I’m thoroughly confused, but I’m determined to understand this. I just wrote the following bit of code will move the current record up to the group that holds the group it is in.

It seems to me both

  1. terribly kludgy
  2. not easily? generalizable (or at all generalizable?)

I’d like to be able to know/calculate through some sort of command what the “depth level” of the current record is (i.e. how many layers down it is). Is there any way to do this? In the immediate future, I’d like to be able to make a subroutine that move an item up x number of levels, and did the error checking necessary to make sure if this means the root level, then it makes the necessary adjustments. I tried doing things like converting y in the script below to a string and doing a word count on it as a way of checking the depth level, but this just produced an error. Has some one else figure out how to do this? Is it possible?




---this code will successfully move a record that is two layers down to its enclosing folder. 

--In other words if you have 
--Top level
----Group level 1
--------Group level 2
------------------record

--and you select record, and then this script will move the record from Group level 2 to level 1. 
--this code will work if you have the record in any level deeper than 2, but it will fail if you have the record at root, or in level 1. 

tell application "DEVONthink Pro"
	set x to selection
	if x is {} then error "please select a record"
	
	set y to first item of x
	set z to the the first item of (the parent of the parent of y) --in other words, to the folder that contains the folder that contains the current item
	set q to the first item of z
	log "about to move"
	move record y to q
end tell


What I probably want is a “get depth from root of record x” command that would allow this subroutine to be written, but if there were any way to determine the depth by anything short of that, I’d be thrilled. I did try “get count of children of x”, but that doesn’t seem to work…

Hopefully other people find this useful! :stuck_out_tongue: Maybe someone will tell me the easier way…

Eric

Here’s a revised script processing the whole selection. In addition, please note that every content can have multiple parents and therefore you have to use “parent 1”.


tell application "DEVONthink Pro"
	copy the selection to theSelection
	repeat with theRecord in theSelection
		-- Not at top level?
		if exists parent 1 of theRecord then
			set enclosingGroup to parent 1 of theRecord
			if exists parent 1 of enclosingGroup then
				move record theRecord to (parent 1 of enclosingGroup)
			else
				move record theRecord to (root of current database)
			end if
		end if
	end repeat
end tell