• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: introspection questions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: introspection questions


  • Subject: Re: introspection questions
  • From: Axel Luttgens <email@hidden>
  • Date: Sun, 02 Feb 2003 11:30:22 +0100

Nathan Herring wrote:

[snip]


III. setting a property through a reference?

if I have a variable set to a reference to a property of an object, how
can I set that property? e.g.,

script a
property x : 1
end script
set aRef to a reference to x of a
set aRef to 2 -- this sets the variable aRef to 2, leaving x of a alone
set aRef to a reference to a
set x of aRef to 2 -- this sets x of a, but I had to know that it was
named x at compile time


This should meet your needs:

set contents of aRef to x


IV. properties, handlers, and scripts by name

I want to be able to refer to handlers, scripts, and properties using a
string variable. e.g.,

property "foo"
handler "bar"
script "baz"

How can I do this?

Say, for example I have an object anObject, and I want to get or set the
property that was passed in to my handler as a string in propertyName.
It would seem I'd have to write out into a temp file something like:

"on getIt(anObject, anApp)
tell anApp to return " & propertyName & " of anObject
end
on setIt(anObject, anApp, aValue)
tell anApp to set " & propertyName & " of anObject to aValue
end"

then load that file using load script and calling the newly formed
getIt(anObject, it) and setIt(anObject, it, whateverValue), which would
bind to the correct item.

I could do the same thing for scripts and handlers, but it seems REALLY
awkward. Is there another way around this?

The standard additions' command 'run script' could help to avoid the temporary file, since it allows to directly (parse/compile/)execute a string you would have constructed.
For example:

script a
on someHandler(x)
return 100 * x
end someHandler
end script

on doThis(scriptObject, handlerName, handlerArg)
run script "on run(params)
tell (item 1 of params) to " & handlerName & "(" & handlerArg & ")
end run" with parameters {scriptObject}
end doThis

doThis(a, "someHandler", 5)
--> 500

On the other hand, not exactly what you asked, but somewhat related:

script a
on someHandler(x)
return 100 * x
end someHandler
end script

set aHandler to a's someHandler
aHandler(3)
--> 300

set aScript to a
a's someHandler(5)
--> 500


HTH,
Axel
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Doing a Save as in Quark
  • Next by Date: Re: Why are compiled scripts slower than from Script Editor?
  • Previous by thread: introspection questions
  • Next by thread: Moving Files by Mod date
  • Index(es):
    • Date
    • Thread