Global smart group UUIDs

I’m trying to figure out how to “target” a Global Smart Group while scripting. I can get a Smart Group Link of the form x-devonthink-smartgroup://A13AF4E4-EC34-4215-82DC-F1ABAD9747A0, but the UUID of that link isn’t usable in get record with uuid actions, unless I’m missing something. (Every attempt to use that idea has yielded missing value.)

Is there any other way to get all of the contents of a global smart group?

Not sure, but I think this is not possible as (as far as I know) smart groups are virtual

That’s correct. Global smart groups & rules aren’t records and therefore not scriptable.

1 Like

Sounds like global group and rule are just collections of internal scripts/codes that are presented as virtual groups displaying in the navigator bar - just curious.

Searching in databases, smart groups in databases and smart groups/rules in the sidebar all use the same engine, therefore the only major difference is how and where they’re stored. But the sidebar is not a database :slight_smile:

Talking about searching and smart groups here’s a handler that checks if one of them is displayed in viewer window 1. Use it to stop a move from script as there’s no way (I know of) to move a specific replicant instance from a search or smart group.

-- Check if a viewer window displays search results or a smart group (in order to stop a "move from" script as it's not possible to move a specific replicant instance of a record)

on noSearchNoSmartGroup()
	tell application id "DNtp"
		try
			try
				set isSmartGroup to false
				set theRoot to root of viewer window 1
				set theRootType to type of theRoot -- global smart group
				if theRootType as string = "smart group" then set isSmartGroup to true --  database smart group
			on error number -2753 -- 
				set isSmartGroup to true
			end try
			
			try
				set searchQuery to search query of viewer window 1
				set searchQuery to searchQuery as string -- search
				set isSearch to true
			on error number -2753
				set isSearch to false
			end try
			
			if isSmartGroup = false and isSearch = false then
				return true
			else
				return false
			end if
			
		on error error_message number error_number
			if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
		end try
	end tell
end noSearchNoSmartGroup

@ryanjamurphy I’m not sure if it’s helpful, but you can pull the UUIDs from the global smart groups’ PLIST file (~/Library/Application Support/DEVONthink 3/SmartGroups.plist).

I’m a terrible coder, but was able to adapt another person’s python script to create an Alfred workflow that allows you to quickly search/open any global smart groups you might have. It’s pretty rudimentary, but it’s lightning-fast and works great in Alfred.

If you’re interested, I uploaded a streamlined version of the workflow for you here: https://share.getcloudapp.com/04uqkmld

2 Likes

Thanks! I can’t even remember why I was looking for this to begin with, but I’m sure I’ll find a(nother) use for it!

1 Like

or use(r) for it :slight_smile:

1 Like

I’m also not sure why one would need the UUID for scripting. But if you insist, here’s a sample JavaScript that looks for smartgroup(s) with a certain name.

   let sgName = "mySmartGroup";
   var app = Application('DEVONthink 3');
   app.includeStandardAdditions = true;
   let smartGroups = app.search("name:" + sgName + "kind:smart group");
   smartGroups.forEach(group => {
     console.log(group.searchGroup().name() + " in " + group.database().name() + " uuid " + group.uuid());
   })
1 Like

@chrillek I might have misread @ryanjamurphy’s original post, but I was under the impression that he was trying to work with UUIDs because he was interested in doing something with the global smart groups - which, to my knowledge, are not accessible through normal means (e.g., they’re not in a database, etc.).

That Alfred workflow I posted above reads the PLIST file where the global smart groups are housed, and spits out a JSON formatted array with their names as the title and UUIDs as the argument, among other things. From there, the user can quickly search through the global smart groups located in their sidebar using Alfred (and the remaining open link portion just adds the following prefix to the selected global smart group’s UUID: x-devonthink-smartgroup://).

In any case, I agree that it’s not for everyone. However, if you’re like me, and have tons of global smart groups in your sidebar that you don’t like scrolling through, Alfred is great for dealing with these sorts of things (and, frankly, it’s just great overall anyway :wink:).

Cheers!

1 Like

PS - for non-Alfred users that might be trying to work with global smart groups, here’s the key bit of python code found in the workflow (see “title” & “arg”):

> #!/usr/bin/python
> # -*- coding: UTF-8 -*-
> 
> import plistlib
> import os
> import json
> 
> filePath = os.path.expanduser("~/Library/Application Support/DEVONthink 3/SmartGroups.plist")
> 
> if os.path.exists(filePath):
>     result = {"items": []}
>     plObjList = plistlib.readPlist(filePath)
>     for plobj in plObjList:
>         result["items"].append({
>             "title": plobj["name"],
>             "uid": plobj["name"],
>             "arg": plobj["sync"]["UUID"]})
>     print(json.dumps(result))
> else:
>     print('{"items": [{"title": "Error","subtitle": "No Smart Groups Found"}]}')

It’s very similar to what you’ll find in Charles Ma’s original workflow, which used the technique to read the user’s favorites from the sidebar. I’ve just adapted it here to read the global smart groups PLIST file.

Hope this helps

1 Like

You’re right, of course. Apparently one can not search for global smart groups.

1 Like

If I recall correctly, here was my use case: I was using Labels to tag tasks across databases. A global smart group then collected all of those task records and I wanted to act on the items via that collection. I came up with some wacky workaround at the time but this would probably have been better.

Alas I don’t use that structure these days. Maybe I’ll return to it!