Re: traversing handlers aren't returning value
Re: traversing handlers aren't returning value
- Subject: Re: traversing handlers aren't returning value
- From: Nigel Garvey <email@hidden>
- Date: Wed, 12 Jan 2005 02:14:54 +0000
Eric Geoffroy wrote on Tue, 11 Jan 2005 08:09:44 -0800:
>
>Bastiaan-
>
>I want to stop the handler as soon as it finds a match for (quark,
>indesign, or framemaker). If I put the "return" inside the handler loop
>it should stop it. It keeps running though.
'Return' only returns to the point from which the current handler was
called. The returns in ProcessFiles() only go back to the current
iteration of processFolders(). From there, you have to return (with the
found value of ft) from each recursion until you get back to the call at
the top of the script.
I haven't tested this rewrite, but it looks roughly OK:
set the foldr to (choose folder)
-- Find text folders
tell application "Finder"
set text_folders_only to folders of the foldr whose name contains
"text"
end tell
set ft to processFolders(text_folders_only, ft)
say "result is" & ft
------ Handlers -----
--Process folders, no font folders. filters "fol" down
on processFolders(foldrlist, ft)
repeat with thisFolder in foldrlist
-- say (name of thisFolder as string)
tell application "Finder"
set fils to files of thisFolder
set fols to (folders of thisFolder whose name does not contain
"font")
end tell
if fils = {} then
-- say "no files in, " & (name of thisFolder as string)
else
set ft to ProcessFiles(fils)
end if
-- If ft is still "", recurse another level.
if ft is "" then set ft to processFolders(fols, ft)
-- If one of the file creators has been found, jump out of the
repeat.
if ft is not "" then exit repeat
end repeat
-- Return from this recursion.
return ft
end processFolders
on ProcessFiles(filesToBeProcessed)
set ft to ""
repeat with thisFile in the filesToBeProcessed
tell application "Finder"
-- say "processing " & name of thisFile as string
set creetor to creator type of thisFile
end tell
if creetor is "XPR3" then
set ft to "Quark 4.11, Mac"
say ft
exit repeat
else if creetor is "Fm70" then
set ft to "FrameMaker 7.0, Mac"
exit repeat
else if creetor contains "InDn" then
set ft to "InDesign CS, Mac"
exit repeat
end if
end repeat
return ft
end ProcessFiles
NG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden