[Help] Getting children of current item's group

Dear all,
I’d appreciate if you could help me on this. Imagine the following scenario:

– We are inside group “Books” which has a group named “Author” which has a group named “Date” which has a PDF document “Text”. Group hierarchy is as follows:

DatabaseRoot > Work > Books > Author1 > Date1 > Text1.pdf
DatabaseRoot > Work > Books > Author2 > Date2 > Text2.pdf
DatabaseRoot > Work > Books > Author2 > Date3 > Text3.pdf

I need to be inside “Books” group because I want to be able to search all the texts coming from all authors and dates, which are many. Imagine I have “Text1.pdf” selected on DT window.


set theAuthor to name of parent of current group

``` retrieves "Work"

set theDate to name of current group


However, I would like to retrieve the author and the date that belong to that text — respectively, "Author1" and "Date1".

How can I do this? I've tried with "child" and "children" and "item" but with no luck so far.
Thanks!

Simplified, the two steps I believe you want are

tell application id "DNtp"
	set theGroup to create location "/A"
	set theResult to search "abracadabra" in theGroup
end tell

This might seem odd – but “create location” will not create a location that already exists, it will just load the address into theGroup. (Use any variable name you wish.) In your example, you could use


set theGroup to create location "/Work/Books/Author1/Date1

Thanks for helping out! Unfortunately I couldn’t make it work… perhaps I misunderstood or didn’t explain correctly. I am also new to Applescript. I’ll try to explain better with the real situation. My interface is as follows:

I am searching [1] inside “I003_bibliografia” group which has as parent “F Fontes Bibliográficas”.
I have then selected the first document [2] and ran the following script:


tell application id "DNtp"
activate
set theAuthor to name of parent of current group
try
	set theAuthor to theAuthor as string
	set tid to AppleScript's text item delimiters
	set AppleScript's text item delimiters to ","
	set theAuthor to theAuthor's first text item
	set AppleScript's text item delimiters to tid
end try

	set theDate to name of current group
	set theName to "{" & (theAuthor as string) & " " & (theDate as string) & "}"
	set the clipboard to theName
	
end tell

After execution this applescript, theAuthor is assigned “F Fontes Bibliográficas” string and theDate is assigned I003_bibliografia.

What I would like them to be assigned, in this case, would be Silva, TMd [3] for theAuthor and 2012 [4] for theDate.

Hope to have explained better!

PS: image is very large to be viewed in the forum and appears to be cropped, but it’s complete on the source.

Thanks.

If I run your script, as is, on this scenario

I get this result on the clipboard


{Bottom Very Bottom}

Is that not what you would expect (and want)?

Perhaps you are selecting the wrong thing (not a group) when you execute the script? In the screen shot a document is selected; which will change the outcome.

Edit. Hang on. I realized you are running the script in the result of a Find operation. The script returns “parent” of a found record as the database. (That probably makes little sense from a scripting perspective, but if you debug the scenario that’s the result.) If you change your script to do a bit of parsing on the path stored in the “Location” property of the found record then I think you can write a script that works both in a “Find” scenario and in a normal view. Hope that makes sense.

Thanks for pointing me in the right direction! I have managed to do it. The solution is dependent on the group hierarchy i.e. it only suits my problem, but with a few tweaks it can serve others as well.

tell application id "DNtp"
	activate
	try
		set selectedRecord to the selection
		if selectedRecord is {} then error "You need to select a record first."
		repeat with theRecord in selectedRecord
			set theRecordLocation to the location of theRecord as string
			if theRecordLocation is not "" then
				set tid to AppleScript's text item delimiters
				set AppleScript's text item delimiters to "/"
				set theAuthor to theRecordLocation's fourth text item as string
				set theDate to theRecordLocation's fifth text item as string
				set AppleScript's text item delimiters to tid
				set the clipboard to "{" & (theAuthor) & " " & (theDate) & "}"
			end if
		end repeat
	on error error_message number error_number
		if the error_number is not -128 then display alert "DevonThink Pro" message error_message
	end try
end tell