Smart Folders in DTTG: an approximate solution

Smart Folders are an extremely useful tool in DT on the Mac, but are currently not available on DTTG. For certain scenarios I find it very useful to have the contents of a DT smart folder available on DTTG. Here is what I do when I have such a smart folder (say smart1) on DT:

  • create a regular folder (group) of the same (or similar) name, say smart1_ in the same DB
  • drag the smart folder to the sidebar onto the smart rule area
  • a smart rule with the same name will appear, and it will contain the search criteria of the smart folder.
  • edit this rule by adding the action Replicate to smart1_ and execute the rule before synchronization.
  • smart1_ will then be accessible on DTTG.

Obviously, this only works with all smart action happening on DT, but that covers the bulk of my needs. Since the smart folder can be dragged onto the smart rule area, this is really quick to set up. If your Mac/DT run all day long, changes made on DTTG will sync back, the smart folder updates, the smart rule kicks in, and the updated “clever folder” as I call it syncs back to DTTG. Near realtime!

N.B.: If the smart folder conditions are edited, the smart rule will not follow, it’s an independent item now. So this works best for relatively stable smart folders.

8 Likes

Thank you for sharing this tip!

This can actually be automated via a smart rule script:

-- Mirror Smart Groups
-- NOTES: 
--	- The smart rule should search only for all or certain smart groups (in one or all databases) and use the trigger "Before synchronization"
-- 	- We add only additional replicants to the mirror, it's up to the user to move all instances of undesired items to the trash
on performSmartRule(theRecords)
	tell application id "DNtp"
		repeat with theSmartGroup in theRecords
			if (type of theSmartGroup as string) is "smart group" then
				set theLocation to location of theSmartGroup & name of theSmartGroup
				set theGroup to create location theLocation in (database of theSmartGroup)
				-- This doesn't add multiple replicants to the same group, therefore no need to check the existence of a replicant first
				-- In addition, this is the most efficient solution and avoids unnecessary changes (and up/downloads)
				replicate record (children of theSmartGroup) to theGroup
			end if
		end repeat
	end tell
end performSmartRule

Could you explain a little bit about how this is supposed to be used? I’m unclear as to where this script should be put, how it should be invoked, etc.

You create a smart rule in the left pane. Something like this:

You choose what locations should be scanned for smart folders. In my case, I want the DB “res2”, and only smart groups in the root location, hence the “exclude subgroup”. Then you need some condition to be fulfilled for the script to act on. I chose to only select smart groups (which is already checked in Christian’s script anyway). Then you want this to act at a suitable moment; as Christian says, the ideal time is “before synchronization”, so that iOS devices always get updated “smart group mirrors”. To enter the script, press “edit script” and paste the above Apple Script in.

There are some caveats. Especially if the smart group looks for tags. For example, I have a smart group “untagged” that lists documents that are untagged. Those would be items in the inbox and groups that are explicitly excluded from tagging. However, the script replicates those files into a real group “untagged”, which, as created, is not excluded from tagging, and boom, from now on, there are by definition no more untagged items, as every items is either tagged otherwise or has the tag “untagged”. Creating those mirror folders, one could give them the “exclude from tagging” attribute. I’m not sure how to do that in AppleScript.

Another issue is that replication into these mirror folders is purely additive. So an item that was part of a smart group at some point, but no longer is because it now no longer fulfills the condition for the smartgroup, will remain there. So technically, every time the smart rule is executed, the existing mirror folders would have to be deleted first, and then re-written. Not sure if that’s what Christian means by

We add only additional replicants to the mirror, it's up to the user to move all instances of undesired items to the trash

With many smart groups and/or many items in them, this could be rather taxing on the sync process, and the trash will be filled with a zillion items, making it hard to monitor the items that you deliberately trashed.

Furthermore, if one has smart groups scattered throughout the DB hierarchy, you suddenly get the DB cluttered with these mirror groups that look like regular groups and that can become a problem, especially if you’re done mirroring (you get rid of a smart group) and they are left hanging there. Deleting them can be a bit of a minefield as you might end up deleting a similar sounding real group. Again, one could automate this by the script deleting the mirror groups before replicating them from the smart group, but giving a script wide-ranging deletion rights feels worrisome.

If using this mechanism, I would use a convention to name smart groups in a unique way, say “my smart group --”, so that one can identify all mirror groups by, you guessed it, making a smart group showing all groups ending with " --". Those can then be summarily deleted without fear as long as you are sure that no normal groups have such a suffix. (Or, smart groups don’t have that suffix, but the script appends something automatically.)

In conclusion, mirroring smart groups is quite an endeavor, I apply it very selectively.

When I do a search for Kind is Smart Group, not all my Smart Group show up? It seems that all the Global Smart Groups didn’t show up. How can I create a smart rule that scanned for all Smart Groups, Local and Global?

@cgrunenberg Will your script works for Global Smart Groups?

Global smart groups as in the ones in the lefthand sidebar, I assume. Good question. I never considered them for this purpose. You want to be very careful with the operations that you want to base on them. The momentary contents of these global smart groups depend on what DBs happen to be mounted at a given time. Furthermore, there is no equivalent of them in DTTG (other than the hardwired ones); of course, you could create the corresponding mirror folder in the Global Inbox, or any other DB.

No, global smart groups cannot be accessed or used in the same way as local ones.

Thanks for all the replies.

I have quite a few Smart Groups that are Global, that is the scope is all open databases, not just a single database.

I started with a few databases hoping that the syncing will be faster. But I keep running into certain things/functions are not working across multiple databases. I might need to combine my databases into a single one to avoid these limitation.