I’ve modified the projects template (Data > New from Template > Productivity > Projects) to create a group/directory structure and includes commonly created files that meets my needs for recurring projects. This works well.
I would like for this template to include Smartgroups that find certain certain records (e.g. all *.EML files or all *.PPTX files only in the project group and subgroups). This works fine if I manually set the “Search In” location for the smart group, but it would be nice to automate this during the creating of the project (as there are several such smartgroups for each project).
Is there a way to automatically limit the scope of the smart group to the group in which it resides (and subgroups thereof), either by specifying a “Search In” location that is relative to the location of the smart group or by creating a smart rule or Applescript that can quickly modify the new smart groups post creation?
I’m not sure about templates, but you can create smart groups programmatically, e.g. in AppleScript. And the documentation says
smart group n > [item] : A smart group.
properties
search group [record] : Group of the smart group to search in.
search predicates [text] : A string representation of the conditions of the smart group.
So, yes, it is possible to set the group and search string in a smart rule with AppleScript
Thanks you for pointing me in the right direction - using this, the following is a working code excerpt that did what I needed in case it is useful to anyone else:
tell application id "DNtp"
activate
set smartGroups to {¬
{name:"01 Emails", predicate:"any: kind:email"}, ¬
{name:"02 Meetings", predicate:"any: tags:Meeting"}, ¬
{name:"03 Logs", predicate:"any: tags:Logs"}, ¬
{name:"04 Documents", predicate:"any: extension==doc extension==docx extension==rtf extension==rtfd extension==scriv extension==pages"} }
set theGroup to current group
set newGroup to create record with {name:"98 Browser", type:group} in theGroup
repeat with sg in smartGroups
create record with {name:name of sg, type:smart group, search group:theGroup, search predicates:predicate of sg} in newGroup
end repeat
end tell
I don’t see what’s Javascriptish here. Looks like normal, well-written, and perfectly functional AppleScript to me
One note: I doubt that you need the "any: " in your predicates. Especially if there’s only one condition
While is may be technically correct, it’s a good habit as it shows an awareness of the aspects of a smart group and adding it is a good habit to be in.
I was referring to the array of records (which would be an array of objects in JS) and the repeat loop. Before this example, I hadn’t seen this kind of abstraction in AppleScript code (probably my bad). In JS, one would write
Because of my limited programming skills, I am using the WikiLinks Template to create sub-documents from a main document that has specific terms. The main document has a word “divestitures” that I would like to explore further by creating a subdocument by placing brackets and clicking on the link.
Question: would it be possible with this template or any other of the Templates provided, to include a SmartRule that would, upon creation of the document, search DTP for the word “divestitures” and within the document place a list of all other documents that have the same word?
I have a (.md) document titled “proxy statement” and where I would like to place information related to proxy statements (what they are, how they work, etc) and inside that document, at the footer, I would like to see all the instances of the word “proxy statement” in my database.
record name with location(s), i.e. in which group etc.?
So, if I understand you correctly, you’d want to search for all documents containing the title of your document and then add (see above) to the footer of your MD.
That could be done with a script. But since I’m away from the Mac with my DT license, I can’t built that now. But you’d have to build the search query and then pass it to the search method. It returns a set of records matching the search criteria and you can then iterate over these records and extract whatever you fancy from them and add it to your MD file modifying that record’s plainText property.
It shouldn’t be complicated, but it might take some time to run.
Since you’re processing the file name as the search term, have you looked at the Tools > Inspectors > Document > Mentions inspector?
Have you also looked at the Tools > Summarize Mentions command?
As backed up by @cgrunenberg using the Mentions inspector is suggested and allows Command-Option-dragging from the inspector into the content of a Markdown or rich text file to insert such links.