Strange behavior for a smart rule that executes a python script

I rewrote an applescript that sets some custom meta data in python using the pydt3 API. I ran the original non-python applescript via a smart rule, so I attached the new python script to the same smart rule via an intermediary applescript:

on PerformSmartRule(theRecords)
	
	do shell script "/Library/Frameworks/Python.framework/Versions/3.12/bin/python3 /Users/samrose/PycharmProjects/set_MetaData/set_MetaData.py"
	
	
end PerformSmartRule

I confirmed that both smart rules do the same thing when applied on demand. However, the python smart rule sometimes doesn’t trigger on import (I never had this issue with the non-python smart rule). It tends to fail about 50 - 60% of the time when I am importing by downloading a file into the global inbox. Once the file is in the global inbox, I can run the python smart rule on demand and it works fine. If I switch back to the original smart rule using the non-python script and re-download the items, the smart rule triggers and runs the script as expected.

The original smart rule attached to the non-python applescript is set up as:

The python smart rule is set up the same way, though I added On Clipping:

I don’t understand enough to troubleshoot the difference. I tried adding ‘On Downloading’ to the python smart rule, but it didn’t help, and I didn’t need to add On Downloading for the original non-python smart rule to trigger in the same situations.

Any ideas on what might be causing the discrepancy?

Show your code, please. And check DT’s log window for any error messages when the Python stuff is not doing what you want it to.

Aside: This is a rather contrived way to solve a presumably trivial problem. Why do you even resort to a Python script if your AppleScript does what you want it to? Why not simply use JavaScript, as pydt3 is only a wrapper around that?

The code is long and shouldn’t be relevant here because (1) I confirmed that the applescript and python code do the same thing when I run both smart rules on demand, and (2) when I apply the python smart rule on demand, it works. Why would a smart rule that can be applied on demand not work when it is being triggered on import? What is different about being triggered on import versus on demand?

As to why python – I was running into issues with scalability with the applescript. Javascript might be a better solution, but I know python better, so I thought I would try it first.

I will look at the logs to try to find more info. Thanks!

Bear in mind, that API is not officially supported by us.