Trouble getting the inbox uuid programmatically

I’m trying to programaticaly get the uuid of a database’s inbox in order to file documents into it.

If I use Script Debugger to examine the database, it tells me the uuid of the “incoming group” of this databbase is “82999D49-4644-438D-854B-4C1BA9D42AC7” and the uuid of the database itself is “B854C0B0-38C5-4159-B0B6-F2EDB9BB9C06”.

However, if i use

set dbUid to uuid of incoming group of thisDatabase as string

on the same database, I get B854C0B0-38C5-4159-B0B6-F2EDB9BB9C06, which is the uuid of the database.
Sure enough, if I then use this uuid to file a document, it will NOT get filed in the inbox. It is in the database (if I search for it or if it’s tagged) but it’s not filed in any group, hence it doesn’t show in DT.

So I have two questions:

  1. how do I get the actual uuid of the inbox in AppleScript?
  2. is filing to the database uuid expected to put the document in this sort of limbo, where it exists in the database but you can’t really see it?

In case of the global inbox the values are identical, otherwise they should be different (and are over here, at least in Apple’s Script Editor.app). Posting the complete script might be useful. However, I actually wonder why you want to use the UUID of the incoming group?

I’m trying to import the selected file into the inbox of a database that I chose at the time of running the macro. The idea is to programatically gather the relevant uuid and then use that to import the file.

I (mistakenly?) thought that the incoming group uuid was what i wanted, but it doesn’t seem so …

Here’s the script i run in KM to gather the uuids:

set nameList to "["
tell application id "DNtp"
    set allDatabases to every database
    repeat with thisDatabase in allDatabases
        set dbName to name of thisDatabase
        set dbUid to uuid of incoming group of thisDatabase as string
        set nameList to nameList & "{" & "\"name\" : \"" & dbName & "\" , " & "\"uuid\" : " & "\"" & uuid of thisDatabase & "\"}" & ", "
    end repeat
    set nameList to texts 1 thru -3 of nameList
    set nameList to nameList & "]"
end tell
set saveTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {","}
set nameList to nameList as string
set AppleScript's text item delimiters to saveTID
return nameList

This makes a JSON object with database name / database uuid pairs.
I then use the “Spotlight Search Prompt macro” in KM to manually select the relevant database uuid and run the following bit of AppleScript:

tell application id "DNtp"
	set dest to get record with uuid theDatabaseUUID
	repeat with currentFile in fileList
		set newRecord to import currentFile to dest
		log message (name of newRecord) & " imported to " & (name of dest)
	end repeat
end tell

where fileList is the list of selected files in the Finder and theDatabaseUUID is the variable that holds the uuid I’ve gathered.

Everything works fine if i manually specify the uuid, but not if i use the “uuid of incoming group of thisDatabase as string” construct.

There’s an issue in the script:

		set dbUid to uuid of incoming group of thisDatabase
		set nameList to nameList & "{" & "\"name\" : \"" & dbName & "\" , " & "\"uuid\" : " & "\"" & uuid of thisDatabase & "\"}" & ", "

dbUid contains the desired UUID but isn’t used in the following line.

Oh god I feel stupid.

Thanks, now it works perfectly! I’ll publish the full set of macros for future references.
That said, you seemed surprised by my use of incoming group, which makes me suspect I’m going about this in a very roundabout way. Is there a simpler way into the inbox?

Cheers.
P.

Usually the incoming group property is of course a better and more readable alternative if it’s only one script but in your case the usage makes sense.

1 Like