• 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: global variable not being recognized by script object subroutine
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: global variable not being recognized by script object subroutine


  • Subject: Re: global variable not being recognized by script object subroutine
  • From: Bill Planey <email@hidden>
  • Date: Tue, 27 Feb 2001 19:56:06 -0600

This is EXACTLY what I needed!!!!

I don't know if I missed it in the 4 or 5 AppleScript books, but
nowhere was it explained that it is not enough to SET a variable
in the origin code, but you must also MARK the invokation of it
(by simply putting "global VariableName" on a line above it...)
in any external handlers/script objects (not merely reference the
variable by its name...

THANKS!!!!!!!!!!!!!!

Bill Planey

>on 2/27/2001 2:10 PM, Bill Planey at email@hidden wrote:
>
>> I did another test, and moved the handler from the script object to a
>physical
>> location within the master script (outside the on run/end run statements).
It
>> still didn't work when called.
>>
>> I fear I am doing something wrong that betrays my relative beginner status
>> with AppleScript.
>
>Hi Bill,
>
>The current variable scope changes depending on where you use the variable.
>Handlers have their own scope which is different than the global scope. By
>default, handlers only know about variables in their local scope. Unless
>you specify that a variable is in the global scope, the handler will assume
>that the variable is in the handler's local scope. Your handler is trying
>to use a variable named AnyDesktop in the handler's local scope, and is
>properly failing.
>
>In the following script, SecondHandler() tells AppleScript that the variable
>AnyDesktop is in the global scope, so that the handler will access the
>variable globally.
>
>my Firsthandler()
>my SecondHandler()
>
>on Firsthandler()
> global AnyDesktop
> set AnyDesktop to path to desktop folder as string
>end Firsthandler
>
>on SecondHandler()
> -- if you uncomment the following line, SecondHandler will access the
>AnyDesktop variable in the global scope
> -- global AnyDesktop
> display dialog AnyDesktop
>end SecondHandler
>
>HTH
>
>JR


  • Follow-Ups:
    • Re: global variable not being recognized by script object subroutine
      • From: JollyRoger <email@hidden>
  • Prev by Date: Re: Write to file - another question
  • Next by Date: Scripting AppleTalk control panel
  • Previous by thread: Re: global variable not being recognized by script object subroutine
  • Next by thread: Re: global variable not being recognized by script object subroutine
  • Index(es):
    • Date
    • Thread