• 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: List acting like a global
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: List acting like a global


  • Subject: Re: List acting like a global
  • From: Nigel Garvey <email@hidden>
  • Date: Thu, 6 Dec 2001 00:47:50 +0000

Jason Bourque wrote on Wed, 05 Dec 2001 09:56:44 -0500:

>Hello,
>
>What's Happening?
>
>tell application "Finder"
> set aList to name of every item of desktop
>end tell
>
>tell me to srListIndexer(aList)
>
>
>
>-- sr2ndListItemFromIndexOf1stList
>set vItemWithIndex to "3 Paper Alligator"
>
>-- Capture the current delimiter for AppleScript
>set vTids to the AppleScript's text item delimiters
>set the AppleScript's text item delimiters to " "
>
>set vItemIndex to (item 1 of text items of vItemWithIndex) as number
>
>-- Reset the delimiter for AppleScript to its previous call state
>set AppleScript's text item delimiters to vTids
>
>item vItemIndex of aList
>--> "3 Paper Alligator"
>
>-- Should be "Paper Alligator"
>-- What's happening?

It's because your handler srListIndexer(aList) prepends numbers to the
names in the list. :-) The list inside the handler *is* the one passed.
Only the variables (whose values are merely pointers to it) are local or
global, not the list itself. The simple way to leave the original list
intact is to make a copy for use within the handler:

on srListIndexer(vAnyList)
copy vAnyList to vAnyList -- set the variable to a duplicate list

-- work on the copy

end srListIndexer

The same applies to any complex object, such as records, dates, folders,
application objects, etc.

NG


  • Prev by Date: Re: List acting like a global
  • Next by Date: Re: Get List of Certain Desktop Filetypes
  • Previous by thread: Re: List acting like a global
  • Next by thread: Re: applescript-users digest, Vol 2 #1368 - 13 msgs
  • Index(es):
    • Date
    • Thread