• 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: JollyRoger <email@hidden>
  • Date: Tue, 27 Feb 2001 21:01:53 -0600

Welcome. Glad to have helped. =)

JR

on 2/27/2001 7:56 PM, Bill Planey at email@hidden wrote:

> 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


References: 
 >Re: global variable not being recognized by script object subroutine (From: Bill Planey <email@hidden>)

  • Prev by Date: Re: Write to file
  • Next by Date: Re: Unspecified unit returned by gestalt call
  • Previous by thread: Re: global variable not being recognized by script object subroutine
  • Next by thread: Replacing range within a string
  • Index(es):
    • Date
    • Thread