Hello.
I’m really trying hard to be able to set and get a property in a script object which are loaded into a script server. The following code is just for illustrating.
The code below breaches everything which I intended to do, as i uses the my keyword, and it’s own name, which would be the same as it got in the server. And even this doesn’t work even it is a totally fake.
script _1_objLib
property txtColor : missing value
on isFavcolor()
log "FAVCOLOR LIB isFavcolor : my new color is : " & (txtColor of my _1_objLib)
if (txtColor of my _1_objLib) is missing value or (txtColor of my _1_objLib) is "" then
return false
else
return true
end if
end isFavcolor
on setFavColor(theColor)
set (txtColor of my _1_objLib) to theColor
log "FAVCOLOR LIB setFavColor() : my new color is : " & (txtColor of my _1_objLib)
end setFavColor
on getFavColor()
log "FAVCOLOR LIB getFavColor() : my new color is : " & (txtColor of my _1_objLib)
return (txtColor of my _1_objLib)
end getFavColor
end script
This is an example of a Small server.
property _1_objLib : missing value
property toplevel : (me)
on run
set my toplevel's _1_objLib to _1_objLib of (load script alias "Macintosh HD:Users:McUsr:Library:Scripts:Modules:favColorLib2.scpt")
on objLib()
return my toplevel's _1_objLib
end run
The client script which calls the Server.m (I assume that the my keyword ends within the application, that is something I will experiment with as soon as this post is written.
tell application "ScriptLibraryServer"
if its objLib()'s isFavcolor() is true then
set myColor to its objLib()'s getFavColor()
tell me
activate
display dialog "FavColor " & myColor
end tell
else
tell me
activate
display dialog "No color defined yet"
end tell
end if
its objLib()'s setFavColor("Blue")
set its objLib()'s txtColor to "Blue"
-- set objLib()'s txtColor to "ORANGE"
log its objLib()'s txtColor ”>(* missing value *)
if its objLib()'s isFavcolor() then
set myColor to its objLib()'s getFavColor()
display dialog "FavColor " & myColor
else
tell me
activate
display dialog "No color defined yet"
end tell
end if
log its (objLib()'s txtColor) ”> (* missing value *)
end tell
I still may have some experiments for giving it totally up, but if some of you know how to do this: (The objective is to be able to set and get a property in a script object in a library loaded into a script server.) Please don’t hesitate.
Also if you are totally sure of that it can’t be done this way at all, but that I have to go through a proper tylist or something. I just want to tell you that the reason for this is encapsulation, I know that I can pass in a parameter from the outside and store that in the client script, that is not the issue. The issue is really to have a separate piece of functionality within a script server, which handles its own data, at least as long as it is running.