Re: varibles in handler
Re: varibles in handler
- Subject: Re: varibles in handler
- From: "Nigel Garvey" <email@hidden>
- Date: Tue, 18 Jan 2011 21:12:16 +0000
"Stockly, Ed" wrote on Mon, 17 Jan 2011 19:59:29 -0600:
>It is possible to set and reset delimiters with something like this:
>-----------
>Set newDelimiter to {", "}
>
>Set {applescript's text item delimiters, oldDelimiters} to {newDelimiter,
>applescript's text item delimiters}
>
>
>--do your stuff here
>
>Set applescript's text item delimiters to oldDelimiters
>-----------
>You could pop that into a handler, make oldDelimiters a global or property
>and change your delimiters with a very simple handler call:
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.
>-----------
>global oldDelimiter
>set newDelimiter to {", "}
>my SetAndSaveTids(newDelimiter)
>--->do your stuff
>my SetTids(oldDelimiters)
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)
if (newDelimiter's class is integer) then
set AppleScript's text item delimiters to item newDelimiter of
originalDelimiters
if (newDelimiter > 1) then
set originalDelimiters to items 1 thru (newDelimiter - 1) of
originalDelimiters
else
set originalDelimiters to {}
end if
return AppleScript's text item delimiters
else
try
set end of originalDelimiters to AppleScript's text item delimiters
on error number -2753
set originalDelimiters to {AppleScript's text item delimiters}
end try
set AppleScript's text item delimiters to newDelimiter
return (count originalDelimiters)
end if
end setDelimiters
set tidRef1 to setDelimiters(".")
set tidref2 to setDelimiters("h")
setDelimiters(tidRef1) --> {""}
NG
_______________________________________________
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