Create getter / setter snippet

Hi,

I’d like to create a getter / setter from a variable with a snippet.

Is it possible ?

Thx.

Can you give us an example of what you are trying to accomplish?

A snippet can certainly generate a pair of handlers (eg. getter and setter), and linked-tags allow an edit in one tag (eg. related names) can be applied to other parts of the snippet.

For example, create a property myProperty : « myValue », select it and invoke a snippet to create a method to get this property like on getMyProperty() return myProperty.

Thx.

Is there some reason you need accessor methods for a property?

Well, for example I have a String lib which contains a uc special chars string (like a constant) :
property ucChars : “AÄÁÀÂÃÅĂĄÆBCÇĆČDĎĐEÉÈÊËĚĘFGHIÍÌÎÏJKLĹĽŁMNÑŃŇ” & ¬
“OÖÓÒÔÕŐØPQRŔŘSŞŠŚTŤŢUÜÚÙÛŮŰVWXYÝZŽŹŻÞ”

Instead of copy it in my script, I’d like to access it. But I don’t know every AppleScript tricks (I used to be a Flash dev during many years) and maybe there is another way ?

Thx.

The simplest way is to use the my keyword:

character 1 of my ucChars

Similarly setting:

set my ucChars to "thisIsAnUglyAndFragileWayOfChangingCase"

Would something like this suffice?

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

set theChars to "AÄÁÀÂÃÅĂĄÆBCÇĆČDĎĐEÉÈÊËĚĘFGHIÍÌÎÏJKLĹĽŁMNÑŃŇ
OÖÓÒÔÕŐØPQRŔŘSŞŠŚTŤŢUÜÚÙÛŮŰVWXYÝZŽŹŻÞ"

(*following 3 lines return a comma delimited list*)
set {saveTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ","}
set theList to items of theChars 
set AppleScript's text item delimiters to saveTID

set myChar to (choose from list theList) as text -- StandardAdditions.osax

Well, not sure to understand…

My property property ucChars : “AÄÁÀÂÃÅĂĄÆBCÇĆČDĎĐEÉÈÊËĚĘFGHIÍÌÎÏJKLĹĽŁMNÑŃŇ” & ¬
“OÖÓÒÔÕŐØPQRŔŘSŞŠŚTŤŢUÜÚÙÛŮŰVWXYÝZŽŹŻÞ” is in a lib “Script A” and I’d like to use it in “Script B” like :
on run
tell script “Script A”
log (ucChars) – does not work
end tell
end run

The only way to get the property is (if i’m not wrong) to create a getter like :
on getUCChars()
return my ucChars
end getUCChars

It is why I asked my question to create that getter automatically with a snippet like in Eclipse.

Thx.

You failed to mention that you meant a property within a script library — that’s quite a different thing.

The short answer is:

tell script "Script A"
	log (its ucChars)
end tell

But that’s not a very good way to address script libraries — you’re generally better off using a use statement. And you also need to be aware that if you’re setting library properties, they are shared between all scripts that access them from the same AppleScript component instance.

The short explaination is : I just want to create a constant in a class and use it in another instead of create it again.

What is the trick with the « use » keyword ?

Thx.

I wouldn’t call it a trick, but this is typical:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use scriptA : script "Script A" version "1.0"

log (scriptA's ucChars)

The version is optional. The assigned variable after the word use is also optional — you don’t need it if the script defines terminology, for example — but when provided is a property of the script.