Perform Smart Rule slow in applescript but not when run manually

If you have suggestions to make it shorter, they are always welcome =).
This may be a newbie question (I’m not a coder), but I am also not able to get the script to run directly. I am using the following:

use script "FileByTags_v71_SR.scpt"
tell application id "DNtp"
set newTagName to "newTagName"
set matchedTag to create location "/Tags/" & newTagName
log message "Created new tag: " & newTagName
-- Run smart rule fileByTags
  tell script "FileByTags_v71_SR.scpt"
  end tell
on error
  display dialog "Err FileByTags smart rule"
end try
end tell

I also tried PerformSmartRule({matchedTag}) and it still didn’t work. Can you clarify how to call the script directly?

I put the FileByTags_v71_SR.scpt in ~/Library/Script Libraries (although if there is a way to just point to the script in the smart rules directory ~/Library/Application Scripts/com.devon-technologies.think3/Smart Rules, that would be ideal because I wouldn’t have to keep it in both places).


What’s actually the purpose of the script? I didn’t analyze its code, not enough time and too much work as usual :slight_smile:

Oh, I didn’t actually expect you to have time to analyze the script. I thought if there were any glaring issues in an ideal world… but that was mostly wishful thinking. My main question is about how to get the script to perform within another script when a new tag is created.

However, just for kicks, the original script takes a tag name that has a specific prefix (defined in the plist file) and looks for additional markers in the tag name that define an action status, year and month and then start with .@ and creates smart groups associated with those markers. For example markers of the form .orgname_ would create a smart group for tags with .@orgname in them. There are different kinds of markers — organizations end with _, names of people end with *, projects start with p and are defined in the plist file, and locations end with $, and general use just start with @ with no end delimiter.

As an example, if I am writing a publication in preparation for the organization ICARDA that is assigned to susan and is a quarterly report that falls under projects irrigation and desalination, which are defined as pIR and pDS, the tag might be pub.PREP.2305.some.description.@ICARDA_.@susan*.@pIR.@pDS.@quarterly. The code would parse the tagname into the different components and create a smart group under PUBLICATIONS (defined in plist) for @ICARDA under orgs, @Susan under names, @IRRIGATION, @DESALINATION, @2023 and @Quarterly. It also creates a smart group for all publications under the PREP actionTag. The code is long because it looks for matches under any possible permutation of the different markers and then orders the markers in the tagname and does a bunch of other little things. The plist file defines a bunch of prefix-specific properties about how I want the matching to go (i.e., maybe I don’t care if the names match for some prefixes) and how I want the smart groups to be organized.

That being said, I really don’t expect you to wade your way through it. If I can just get it to run in my other scripts that happen to create new tags.