• 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: "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

  • Follow-Ups:
    • Re: varibles in handler
      • From: "Stockly, Ed" <email@hidden>
  • Prev by Date: Copying unicode from Excel and pasting to text file
  • Next by Date: Re: varibles in handler
  • Previous by thread: Re: varibles in handler
  • Next by thread: Re: varibles in handler
  • Index(es):
    • Date
    • Thread