Smart Rule scripts supporting inline AppleScriptObjC

I’ve recently seen posts where users used inline AppleScriptObjC in Smart Rules.

In the past it wasn’t possible to do that, instead we needed to call a script library. As I couldn’t find a mention of this new behaviour in the help I was sure that it won’t work.

Now tested and … whooooaaaaahhh … it’s possible now!

Thanks so much!!

-- Test - Smart Rules - Is inline AppleScriptObjC possible

use AppleScript version "2.4"
use framework "Foundation"
use scripting additions

on performSmartRule(theRecords)
	set theArray to current application's NSMutableArray's arrayWithArray:{"1", "2", "3"}
	set theList to theArray as list
	set theList_string to my tid(theList, linefeed)
	display dialog theList_string
end performSmartRule

on tid(theInput, theDelimiter)
	set d to AppleScript's text item delimiters
	set AppleScript's text item delimiters to theDelimiter
	if class of theInput = text then
		set theOutput to text items of theInput
	else if class of theInput = list then
		set theOutput to theInput as text
	end if
	set AppleScript's text item delimiters to d
	return theOutput
end tid
1 Like

Actually there was no related change in DEVONthink, I’m not even aware that this wasn’t possible :confused: :confused:

It definitely wasn’t possible in the past, tried it myself, more than once.

After it didn’t work back then I searched the forum and found this thread. In this thread @clang thankfully came up with the solution of moving ASObjC into a script library. Since then I’ve been using his approach.

Again, tested quite often, it wasn’t possible in the past.

That’s unfortunate. As a forum search revealed others who already mentioned this problem I didn’t think about reporting it.

It’s sunday, what are you doing here after all? :slight_smile:

Thank you for mentioning this. I had been working (for far too long) on some new AppleScript code for smart rules, and after a ridiculous amount of time getting it working (in a debugger, outside of DEVONthink), when I put everything together in a smart rule, I got the dreaded error -1708. After searching and finding discussions in this forum, it seemed like the only solution was to set things up as a script library – not terrible, but would have required even more work and time. This posting of yours gave me a glimmer of hope that it could be made to work somehow, and that the root of the problem had something to do with scoping or type conversions or collisions of some sort. It inspired me to keep searching, and eventually to a discovery described in this posting:

1 Like