I apologize in advance for beating a perhaps dead horse. I for one would find it helpful to be able to have a smart rule pass argument lists ala sh/bash/zsh etc to scripts invoked by smart rules. It would also be useful to receive the output from the called scripts.
I have cobbled this together myself by using custom metadata items for example, finding a particular date using regular expressions then passing the string to a script that did some manipulation of the date and then returning the manipulated date back through another custom metadata then using that returned value later in the smart rule flow.
I think it would be useful to have a more standardized approach baked into DT. Perhaps DT4 ?
maybe as simple as âstandardâ metadata definitions?
Thanks
A concrete example would be useful.
Also, there is the Script with Input/Output smart action in DEVONthink 4 that can return a value for subsequent actions.
1 Like
Thank you for your timely response. I will try and elucidate a specific example, but I will also take a look at DT4 documentation for the âScript with Input/Outputâ smart action.
My example is that I have documents that contain a date that I wish to be the âDocument Dateâ. This date can not be found by the usual âScan Textâ Date Action. I am able to find the date using a regular expression but I also wish to transform the date from a Month Day, Year into a YYYY-MM-DD format for use in renaming. I have written an AppleScript that does this by populating custom metadata fields for the input and output of the script. This works for me but a more âstandardâ approach supported by DT would be preferable and applicable to other DT users.
Again, thanks for the help. I am off to check DT4 documentation for the feature you mentioned.
So I have looked at DT 4âs Script with Input/Output smart action and it looks like it is exactly what I was asking for in my request. I did download the beta and tried that action. I could not make it work reliably but given that it is a beta that is not unexpected. Are you looking for DT 4 beta feedback? If so, what is the process for providing that feedback?
I could not make it work reliably but given that it is a beta that is not unexpected.
I can hazard a quess what youâre doing wrong but did you read the Automation > Smart Item Scripts section in the Help?
Are you looking for DT 4 beta feedback? If so, what is the process for providing that feedback?
Of course! This is a beta test, not an early access program, so our hope is people are actually testing and reporting, not just filing feature requests.
I have done some more testing on DT4âs Script with Input/Output smart action feature. I have tested in both a new user environment as is recommended, although Devonthink 3 is still available to run. I did not want to hinder my normal use of DT3. I have made sure that the new user has not accessed DT3 and verified by examining ~/Library/Application Support. There are no DT3 files, only DT4.
I also setup a parallels macOS virtual machine to further isolate my testing. That VM is running the same OS as my current system. Aside from the usual applications which come with a new macOS install, only DT4 is installed. I was pleasantly surprised that DT4 did install and seemed operational.
Cut to the chase. I tested the Script with Input/Output feature in both environments with similar although not exactly the same results. Briefly, I took a Devonthink 4 supplied script from the available choices and modified the script to do nothing but take a selected record and the ScriptInput value and write a log message to the DT log. The script then returns the script input to the ScriptOutput placeholder. Thatâs it.
I first ran this script against around 300 selected pdf+text items. The script did not log ANY messages. I waited for a good amount of time and then went to run the script again from the left sidebar by selecting the smart rule that contained the call to the script. Interestingly the âApply Ruleâ entry in the pop-up/pop-over no longer appeared. I went to the item list of DT4 and again the âApply Ruleâ option did not appear.
I was able to select a different smart rule in the side bar, and it did allow me to apply a different smart rule, which called the normal DT3 type of script, but when I ran it, it did not do anything.
I then restarted DT4 and reversed the order of executing the smart rules. The DT3 type smart rule performed normally on a set of > 300 items. I ran it multiple times and it performed normally each time. I then ran the ScriptOutput smart rule with the same set of items and again it failed in the same way.
I then restarted and then tested the ScriptOutput smart rule with a smaller set of items. I was able to successfully execute the smart rule repeatedly with an increasing number of items until I reached 63 or 64 items. The number of items varied from the virtual environment and the new user environment with the VM doing 64 and the real environment doing 63 items. I repeated a number of times in both environments with the same results.
There were no crashes or âbeachballâ hangs in any of the tests. Parts of the app were responsive but I did not pursue any of that.
Hope this is useful, if you have any questions or suggestions. please let me know.
Please show your code and screenshots of your setup.
There are a lot of reasons why the script doesnât do what you expect. How are we going to be able to help you without seeing what you do exactly?
Smart rule scripts should only use the record(s) parameter but not the selection actually.
This code
function scriptoutput(record,input) {
const app = Application("DEVONthink");
app.logMessage(`Input: ${input}`);
}
does exactly what it is supposed to do in this smart rule
So, I doubt that anything is broken with the Script Input Output stuff. Thatâs why it is important to post the code and the contest instead of only prosa.
And of course: Scripts in smart rules work on the record(s) passed in as parameters (thatâs the whole point of having the script in a smart rule in the first place), not on the current selection.
I reset my test setup to anonymize the data so I could be comfortable sharing screen shots.
- Here is a screen shot showing the smart rule âTestâ and the database after running the smart rule again a subset (60 records). It shows that the rule and called script worked and populated the âFinder Commentsâ Annotations.
-
Here is the AppleScript source called.
Testscript.pdf (25.5 KB)
-
Here is screen shot showing the run with 61 records. and the log. Worked fine.
- Then a screen shot run against 64 items. showing no logged items and the âApply Rulesâ menu item gone missing. Also the sidebar âApply Ruleâ menu item is missing after this run but I spare you another screen shot.
I hope this helps. Perhaps you can recreate this in your own testing?
How does it behave with an embedded script?
By the way, is this academic or do you actually anticipate processing 300 items on a regular basis?
@cgrunenberg: I did see the Apply Rule disappear from the context menu after running the rule on 250+ documents.
However, it inconsistently shows with other rules.
Double-clicking the rule and okaying, without changes, brings the command back.
(beta on Sequoia).
I can achieve my goals using existing DT3 functionality. I am using DT to manage historical financial reports from multiple banking, investment and credit card accounts so I do routinely process a fair number of items. I like your product and would like to do all I can to support it and improve it when I can. I have not tried an embedded script.
I am willing to continue to provide information as needed.
Christian, was the smart rule functional after you ran it and then made it reappear?
I ran the same tests with the same script but embedded instead of external. Same results.
DEVONthink 4 executed too many scripts concurrently, AppleScript didnât like this at all
The next beta will fix this.
1 Like
Thank you for the update. Look forward to the next release.
FYI @paterfam here. I am pleased to report that I updated to 4.0beta3 today. I reran my tests against this codebase with no errors. I ran the test script I shared earlier in this thread both embedded and external. No problems or errors detected. I increased the number of records to over 7000 and was able to run and rerun successfully.
Thank you for the opportunity to test.
3 Likes
Thank you for the feedback, good to know that itâs really fixed.