Saturday, April 29, 2017

#1 2017-04-15 04:33:05 pm

tempel
Member
From: Germany
Registered: 2010-11-19
Posts: 59
Website

Getting only the writable properties of a class

Is there a standard AppleScript construct to get only those properties of a class that are settable?

I ask because I'm writing a scriptable app, and I want to make it possible to use "make new ... with properties X", where X are properties fetched from another object of the same class. I do not want to use duplicate for this (because I do not want all the elements duped), so I am looking for a convenient way to copy just the top properties from an existing object to the new one.

Ideally, one should be able to write something like this:

Applescript:

set oldObject to ...
set oldProps to writeable properties of oldObject
make new myClass with properties oldProps

Of course, "writeable properties" is not a valid construct, and so the above leads to a syntax error.

But if I just used "properties", that would include read-only props, and if I passed those to the "make" command, it would internally complain about trying to set read-only properties.

Any ideas how to solve this elegantly?

I can add new keywords, of course, but I first wanted to see if there are common ways to do that already.


Filed under: Properties, Make

Offline

 

#2 2017-04-16 07:04:13 am

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 4998

Re: Getting only the writable properties of a class

I don't think there's such a construct, unfortunately. You could always follow the lead of InDesign, which ignores any errors as long as there is as least one valid property value in the list of properties you pass. It was designed that way to solve the very problem you are trying to address.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#3 2017-04-16 11:03:28 am

tempel
Member
From: Germany
Registered: 2010-11-19
Posts: 59
Website

Re: Getting only the writable properties of a class

Hi Shane,

I'm glad to see I'm not the first running into this challenge, then smile

I had considered that solution as well, but didn't want to allow assigning to read-only properties at all times.

But then I realized that I can tell whether the properties are set during a "make" or "duplicate" command, and now I simply suppress the error during execution of those commands.

But before I did that, I also extended the duplicate command instead, with a new parameter that takes care of what I wanted to achieve. More options for the user, yay! ... Which pretty much counters the direction Apple is going, which is to reduce the options to a computer user more and more wink

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.047 seconds, 8 queries executed ]

RSS (new topics) RSS (active topics)