• 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: On Run handlers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: On Run handlers


  • Subject: Re: On Run handlers
  • From: Michael Terry <email@hidden>
  • Date: Wed, 11 Feb 2004 19:11:42 -0800

On Feb 11, 2004, at 3:27 PM, Dan Doughtie wrote:

I can't get the on run handler to work correctly because when it runs it
can't seem to pass the variables to the subroutines. If I frame the entire
script sub routines and all it won't run.

If I frame all of the basic script and put the END RUN in front of
subroutines the subs fail.

I also ran into this with folder actions. How do you properly frame a script
so that the subroutines continue to run.


What do you mean mean by framing the script? Framing it within an explicit run handler? I thought that's what you meant, but you can't put handler definitions inside a run handler at all and have it compile, let alone run.

You can put handler definitions inside an implicit run handler (there's really hardly any helping it). If you have an explicit run handler then other handler definitions need to be outside of it.

------------------------------------------
Implicit:

set x to 1
display dialog x

on a()
--do some stuff
end

Explicit:

on run
set x to 1
display dialog x
end

on a()
--do some stuff
end
------------------------------------------

What's the error you get when the subroutines fail? Is it 'variable varName is not defined', where varName is the name of one of your variables? If that's the case, it's because the variable is not in scope. Usually, the preferred way to handle this is to pass the values you want the subroutines to use to the handler as arguments:

------------------------------------------
set x to 1
a(x)

on a(val)
display dialog val
end
------------------------------------------

If you want to use global variables, first be sure to understand that that's what you're doing. Undeclared variables at the top level of the run handler have a type of global scope. They're globally available for anyone who wants them, but other routines specifically have to ask to see them. This is done via the 'global' keyword.

------------------------------------------
on run
set x to 1
a()
end

on a()
global x
display dialog x
end
-- 1

on run
set x to 1
a()
end

on a()
display dialog x
end
-- error
------------------------------------------


Mike
_______________________________________________
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.

References: 
 >On Run handlers (From: Dan Doughtie <email@hidden>)

  • Prev by Date: Re: On Run handlers
  • Next by Date: copying files
  • Previous by thread: Re: On Run handlers
  • Next by thread: Efficient searching of Address Book
  • Index(es):
    • Date
    • Thread