Running a script from a smart rule

I copied the built-in script (as clutter free pdf) from DOWNLOAD folder to SMART RULE folder and it now appears as an option in Smart Rule. But, it won’t run from there. It runs fine from the menu but I can’t automate it to convert DevonAgent results (from FILE RESULTS IN DEVONTHINK script) to uncluttered PDF. I can’t use convert because uncluttered is not an option there.

I know that there was a discussion here about this error (1708) but that user was trying to run a script that was controlling another app.

i have tried rebooting. And tried to trigger rule during import, on creation and on demand.

For the public record, I solved this by adding these two lines at the top and bottom of the script:
on performSmartRule(theRecords)
end performSmartRule

That’s it.

Well done on helping yourself, and thanks for leaving knowledge here for posterity :+1:t3:

I have a similar issue trying to run “Update indexed items of all databases” from a smart rule. I have copied the original script to the smart rules folder and added the lines

on performSmartRule(theRecords)
end performSmartRule

The entire script is below. I keep getting the error-1708.

Any thoughts please?

Thanks Chris

– Update indexed items of all databases

– Created by Christian Grunenberg on Tue Mar 25 2014.

– Copyright (c) 2014. All rights reserved.

– Set to true if indexed items are not only located at the root of the database

property pAllRecords : false

on performSmartRule(theRecords)

tell application id “DNtp”

try

set theDatabases to databases

show progress indicator “Updating Indexed Items” steps (count of theDatabases)

repeat with theDatabase in theDatabases

step progress indicator (name of theDatabase as string)

set theRecords to records of theDatabase – Children of root

repeat with theRecord in theRecords

if pAllRecords or theRecord is indexed then

synchronize record theRecord – Updates children of theRecord too

end if

end repeat

end repeat

hide progress indicator

on error error_message number error_number

hide progress indicator

if the error_number is not -128 then display alert “DEVONthink” message error_message as warning

end try

end tell

end performSmartRule

This is a very old, discouraged and buggy script. Try if pAllRecords or indexed of theRecord then instead.

Thanks. Will update and try again.

I have amended as suggested, compiled, closed dbase and DT., reopened and run smartrule again, still getting error-1708. Any ideas please?

If you post code, please include it in three backticks like so:
```
code goes here
```

As to your question: Please check thoroughly what happens to your theRecords variable, i.e. the parameter that is passed into the performSmartRule handler. Using a more useful variable name (eg selectedRecords instead of theRecords and currentRecord instead of theRecord) might help in understanding what’s going on.

Noted re … Thanks for the tip.

I , perhaps rather naively, copied the script from the script library that downloaded with DT. The script runs fine when not run through a smart rule.

I had hoped that with the addition of

on performSmartRule(theRecords)
end performSmartRule

as suggested at the top of this thread that I could achieve what I want. I am not experienced with Apple Script but will try to follow your suggestions. Thanks for your help.