• 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: applescript-users digest, Vol 3 #2135 - 16 msgs
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: applescript-users digest, Vol 3 #2135 - 16 msgs


  • Subject: Re: applescript-users digest, Vol 3 #2135 - 16 msgs
  • From: Graff <email@hidden>
  • Date: Fri, 07 Nov 2003 04:31:29 -0500

You are right that recursive algorithms have their troubles, one of which is the possibility of overflowing the stack. A list-based algorithm also can have its own troubles, namely that it might overflow the maximum size of the list data type that you are using to contain all of the folders or it might run out of the memory needed to contain a very large list.

However that being said, here is a script similar to the recursive one that I posted. This one replaces the recursion with a list to do its work. I'm not sure if it is more or less efficient or "correct" but both the recursion and the list based scripts seem to work just fine.

- Ken

code:

--this runs if the icon is double-clicked
on run
set badfolder to choose folder with prompt ,
"Choose a folder with bad picture files"
clearcomment(badfolder)
end run

--this runs if a file is dropped on the icon
on open openedfolder
set badfolder to openedfolder as alias
clearcomment(badfolder)
end open

-- here is the main function
on clearcomment(badfolder)
set folderList to {}
copy badfolder to the end of folderList

-- the meat of the function, uses a list to keep track of folders that need clearing
repeat while length of folderList is greater than 0
tell application "Finder"
set currentFolder to the first item in folderList
set folderList to the rest of folderList
set comment of every item in currentFolder to ""
set newFolders to every folder of currentFolder
set folderList to folderList & newFolders
end tell
end repeat

beep
display dialog "Comments Cleared" with icon note giving up after 2
end clearcomment

On Nov 7, 2003, at 2:20 AM, Emmanuel wrote:

But maybe I'll help someone by recalling that it is usually no good programming practice to use recursion in AppleScript where it is not fully required. When you use recursion, you are making a script which will work until the day when you really need it - that day when you've really got complex hierarchies and your script will hit the Stack overflow limit.

AFAIK, most recursive algorithms can rather easily be turned into memory-consuming but stack-savvy algorithms where you just maintain a FIFO list of the items to process: e.g. when you hit a folder, you append its contents at the end of the list.
_______________________________________________
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.

  • Follow-Ups:
    • Re: applescript-users digest, Vol 3 #2135 - 16 msgs
      • From: Emmanuel <email@hidden>
References: 
 >Re: applescript-users digest, Vol 3 #2135 - 16 msgs (From: Graff <email@hidden>)
 >Re: applescript-users digest, Vol 3 #2135 - 16 msgs (From: Emmanuel <email@hidden>)

  • Prev by Date: AppleScript Studio and Filemaker
  • Next by Date: Re: applescript-users digest, Vol 3 #2135 - 16 msgs
  • Previous by thread: Re: applescript-users digest, Vol 3 #2135 - 16 msgs
  • Next by thread: Re: applescript-users digest, Vol 3 #2135 - 16 msgs
  • Index(es):
    • Date
    • Thread