1

In my scriptable Mac app, I like to make the following syntax possible:

set preference with key <a key> to <a value>

Is that possible? How would I specify this in the Sdef?

The only way I can so far come up with is to define a command with the name set preference with key, but Apple's Scripting Interface Guidelines says that one should not begin a command with a reserved name such as set is here. Is there any other way? Or is it safe to use my idea in this case?

Currently, I avoid this by instead using this, but I don't like that syntax as much as I'd like the more common "set" terminology:

write preference with key <a key> value <a value>

Better suggestions are welcome.

Thomas Tempelmann
  • 11,045
  • 8
  • 74
  • 149
  • Create a class for your preferences using an `AppleScript Object Model`. Then create read/write properties for it. – dj bazzie wazzie May 13 '16 at 14:53
  • @djbazziewazzie You're right. I could do that, and that's probably the cleanest solution. I rather avoid the work that's required for that right now, though, and take the above shortcut. I don't expect more than a handful of people in the world to use this anyway, so this is mainly educational for me :) – Thomas Tempelmann May 13 '16 at 15:44
  • @djbazziewazzie is right. Take the time, do it correctly. – Mark Alldritt May 13 '16 at 22:56
  • I have to agree with dj and Mark. A simple UserPreferences class with some properties, a few entries in the SDEF, and you're done. Additionally, the terminology using key/value in the question strikes me as thinking like a cocoa programmer, instead of like a AS scripter. I'd much prefer terminology such as `set nickname of user preferences to "bubba"` and `properties of user preferences` – Ron Reuter May 16 '16 at 03:31

0 Answers0