-- Replicate record to root if its only parent is a Tag
tell application id "DNtp"
try
set theRecords to selected records
if theRecords = {} then error "Please select some records."
show progress indicator "Verifying parents... " steps (count theRecords) as string with cancel button
repeat with thisRecord in theRecords
step progress indicator (name of thisRecord) as string
set theParents to (parents of thisRecord whose location does not start with "/Tags/")
if theParents = {} then
replicate record thisRecord to root of database of thisRecord
set theTags to tags of thisRecord
set tags of thisRecord to {} -- necessary to reassign "parent 1" to a non tag record
set tags of thisRecord to theTags
end if
end repeat
hide progress indicator
on error error_message number error_number
hide progress indicator
if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
return
end try
end tell
Edit:
In case someone wonders why tags are temporarily removed:
Without that asking in a script for parent 1 still would return one of the tags. That means any script that uses parent 1 would then act on a tag and not on a group, i.e. we would likely run into trouble which hardly can be tracked down.