• 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 15:29:43 -0600

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: folder action help
  • Next by Date: Re: Write to file
  • 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