How can Applescripts in Smart Rules access the path of watched group?

I’m doing more with Smart Rules - they are very handy! :slight_smile:

Often I use Smart Rules executing an embedded Applescript. In this Applescript it would be super-cool if I knew the path of the group this Smart Rule is searching in. (This is the group you select at the top of the Smart Rule underneath the rule name.)

Is it possible to find out this path in the Applescript?

This isn’t possible. What exactly do you have in mind?

Fair enough. It would be just convenient in my two use cases:

  1. I gradually move things from normal filesystem folders into DT groups. So new documents which come should get moved into the DT group as long as there is no duplicate in a corresponding filesystem folder. The critical part here is “corresponding”: If the Applescript could know which DT group the Smart Rule watches I could just duplicate a given rule, adjust which group it watches and the Applescript would check the corresponding folder.

  2. I have a rule which updates some custom metadata from OPF files in a parallel folder on the filesystem. This is only one rule, but I have a second test rule which does the same thing for a test group. - Would be nice to have both rules the same, just watching different groups (and acting on corresponding OPF folders).


I can’t remember what exactly it was, however I also had a situation where I liked to access the search group from within a Smart Rule script. Wasn’t possible so I gave up on this one.

I don’t quite follow what you’re after but since you’re targeting a specific group, the matches are all children of that target group. If that’s the case, something like this would detect the parent.


Baaam! Very nice!


Unfortunately this won’t work reliably as records can have more than one parent (as you know :slight_smile: ).

Yes, I’m aware of this so one has to be thoughtful if they are using replicants.

on performSmartRule(theRecords)
	tell application id "DNtp"
		repeat with theRecord in theRecords
			set recLocation to (location of theRecord) as string -- Check the location
			set recParent to {location, name} of parent 1 of theRecord -- The the location and name of the parent
			set recDatabase to database of theRecord
			if (recLocation = (recParent & "/" as string)) then -- Compare the location and (parent + "/")
            -- If they match, then parent 1 is equal to this location.
				display notification (name of recDatabase as string) & ": " & (recParent as string)
			end if
		end repeat
	end tell
end performSmartRule


A bit :stuck_out_tongue_winking_eye: No, seriously I don’t understand what you’re doing there. How does that help to find the group the Smart Rule is searching in? Or isn’t that what it should do?

As I said, if a specific group is being targeted then every matched item is a child of that group. That means the item’s location includes the target group.

Getting the parent of the matched item should be sufficient if there are no replicants involved.

But if replicants are involved, a file can have more than one parent, so checking the location of parent 1 of a matched item against the location of the record would determine if the targeted group is the first parent of the file. “Is parent 1 of the matched file and the location of the matched file the same?”

And since the location doesn’t contain the name of the group, I string them together with a trailing slash to compare with theRecord’s location.

This is pretty smart, Jim! Thanks.

You’re welcome.