• 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: varibles in handler
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: varibles in handler


  • Subject: Re: varibles in handler
  • From: Axel Luttgens <email@hidden>
  • Date: Wed, 19 Jan 2011 17:46:50 +0100

Le 18 janv. 2011 à 22:12, Nigel Garvey a écrit :

> [...]
>
> Although Robert wanted a global, a variable for storing TIDs would
> ideally be local so that handlers could set and restore TIDs without
> interfering with the settings in the places from which they were called.
> [...]
> But I thought it might be interesting to have a go at a one-handler-does-
> it-all solution and came up with the following. It's comparatively long-
> winded, but convenient to use. When you pass it some text, its sets the
> TIDs to that value, stores the old value in a global list, and returns a
> reference index for it. When you pass it the reference number, it
> restores the relevant old value, removes it (and any after it) from the
> list, and returns it for good measure.
>
>  global originalDelimiters
>
>  on setDelimiters(newDelimiter)
>    [...]
>  end setDelimiters
>
>  set tidRef1 to setDelimiters(".")
>  set tidref2 to setDelimiters("h")
>  setDelimiters(tidRef1) --> {""}


Le 18 janv. 2011 à 22:40, Stockly, Ed a écrit :

> Pretty nifty!
>
> One suggestion, it might help to put the global declaration inside the
> handler. There are some scoping issues that require it, and it's really not
> needed anywhere else in a script. (In cases where it its simply declare it
> in those handlers too.)


Alternatively, perhaps could it prove useful to define a script:

	script TID
		property originalDelimiters: {}
		on setDelimiters(newDelimiter)
			[...]
		end setDelimiters
	end script

	set tidRef1 to TID's setDelimiters(".")
	[...]

That way, one would have a single name (the script object's name) in the namespace anymore (instead of two: originalDelimiters and setDelimiters) as well as avoid any scoping and persistency issues coming with global variables.

Just a thought ;-)
Axel


PS - Since the text item delimiters are usually handled in (possibly nested) push/pop sequences, one could also consider something like this:

	script TID
		property stack : {}
		on reset()
			set stack to {}
			set AppleScript's text item delimiters to {""}
		end reset
		on def(newDelimiter)
			set beginning of stack to AppleScript's text item delimiters
			set AppleScript's text item delimiters to newDelimiter
		end def
		on undef()
			set AppleScript's text item delimiters to item 1 of stack
			set stack to rest of stack
		end undef
	end script


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Re: varibles in handler (From: "Stockly, Ed" <email@hidden>)

  • Prev by Date: Setting QuickTime Player 7 Preferences
  • Next by Date: Re: Setting QuickTime Player 7 Preferences
  • Previous by thread: Re: varibles in handler
  • Next by thread: Re: varibles in handler
  • Index(es):
    • Date
    • Thread