Re: Handler works only once
Re: Handler works only once
- Subject: Re: Handler works only once
- From: has <email@hidden>
- Date: Thu, 20 Feb 2003 17:21:41 +0000
Rich Carroll wrote:
I seem to be having a problem with a handler working only the first time
thru. If I call it again, I get "Finder got an error: Can't continue
wrangleName" (handler name) error.
All messages - application/osax commands and handler calls - are sent
to the target of the current tell block. And here's your problem:
your script is sending a wrangleName message to the Finder instead of
itself:
======================================================================
on changeName(folderPath)
tell application "Finder"
...
wrangleName(folderName, folderPath) -- !!!
...
end tell
end changeName
======================================================================
The Finder is complaining because it doesn't understand the
wrangleName message, and nor does AppleScript when the Finder tries
to pass the message on to it.
What you need is some way to send the wrangleName message to your
script instead. AppleScript defines a special global variable, 'me',
which always contains the current script, so just direct the call
there:
tell me to wrangleName(folderName, folderPath)
or:
wrangleName(folderName, folderPath) of me
or:
my wrangleName(folderName, folderPath)
HTH
has
--
p.s. The code you posted was pretty convoluted. Below is a cleaner
version which you're welcome to use. (It also does error handling and
recording, which avoids it stalling on problem names.)
======================================================================
-- constants
property cValidFileNameChars : "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijk
[NO-BREAK]lmnopqrstuvwxyz1234567890" as Unicode text
--handlers
on stripInvalidChars(txt, validChars)
set res to ""
repeat with charRef in txt
if charRef's contents is in validChars then
set res to res & charRef
end if
end repeat
return res
end stripInvalidChars
on renameItem(itemRef, errorsList)
tell application "Finder"
set itemName to name of itemRef
set newName to my stripInvalidChars(itemName,
[NO-BREAK]cValidFileNameChars)
if (count of newName) = 0 then
set end of errorsList to "Can't rename " & (itemRef as
[NO-BREAK]alias) & " to \"\"."
else
try
set name of itemRef to newName
on error eMsg
set end of errorsList to "Can't rename " & (itemRef as
[NO-BREAK]alias) & " to \"" & newName & "\" due to error: " & eMsg
end try
end if
end tell
end renameItem
on processFolder(theFolder, errorsList)
tell application "Finder"
repeat with itmRef in (get every item of theFolder)
if class of itmRef is folder then my processFolder(itmRef,
[NO-BREAK]errorsList)
my renameItem(itmRef, errorsList)
end repeat
end tell
end processFolder
on run
set theFolder to choose folder with prompt "Select folder to be
[NO-BREAK]checked."
set errorsList to {}
processFolder(theFolder, errorsList)
renameItem(theFolder, errorsList)
return errorsList
end run
======================================================================
--
http://www.barple.pwp.blueyonder.co.uk -- The Little Page of AppleScripts
_______________________________________________
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.