Can't write a property through ScriptingBridge

Staring to use ScriptingBridge in Swift to enable faster scripting access to an external app (Devonthink) and therefore avoid having to use an AppleScript as a conduit to call a Swift command line utility and deal with its results.

The plan is to be able to read the plaintext of a record (no problem) and change the record name in Devonthink based on its contents. But I can’t seem to write to a property, instead getting an error “Cannot assign to property: ‘***’ is immutable”.

Any guidance how to get around this?

Can you write the same property with AppleScript?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

How are attempting to set the property? And how are you defining the scripting API for DevonThink?

Assuming you've got the right API mapping, properties cannot be set directly — you have to use their corresponding setter method, e.g. setName(_ name: String).

For example:

let url = URL(fileURLWithPath: "/System/Volumes/Data/Applications/DEVONthink 3.app")
guard let application = SBApplication(url:url) else { return }
let devonThink = application as DevonThinkApplication
    
// Change name of the currently selected record
let currentRecord = devonThink.contentRecord
currentRecord?.setName?("new-name.md")

If that's not working, then the scripting API was defined incorrectly.

Can't write a property through ScriptingBridge
 
 
Q