Dear Friends,
Another very basic, should be simple question. In OS 9, if I put a “handler” script in the folder with my parent script, it seemed to work. Now I’m at a loss!
Parent:
tell application “Finder”
activate
set the_sel to (selection)
set sel_item to (first item of the_sel)
set Target_Folder to (container of sel_item)
set File_Name to (name of sel_item)
set the_ext to (name extension of sel_item)
if not (the_ext is “pdf”) then
if (File_Name ends with the_ext) then
set File_Name to (text 1 thru -5 of File_Name)
end if
end if
set prevAppleScriptdelimiters to AppleScript’s text item delimiters
set AppleScript’s text item delimiters to {“_”} --set the delimiter you like
display dialog "A. Usable string: delete only, press “OK”
B. Unuseable string: delete unneeded, press “Switch” or “Continue.”" default answer File_Name ¬
buttons {“Cancel”, “Continue”, “OK”} default button 3
if button returned of result is “OK” then
set theTruncatedFindingName to text returned of result
set theWorkingName to theTruncatedFindingName
else if button returned of result is “Continue” then
set theTruncatedFindingName to text returned of result
display dialog “Rearrange until you have a name of the form:
given; given_family; or given_middle_family
(where capitalization doesn’t matter):” default answer theTruncatedFindingName ¬
buttons {“Cancel”, “Switch”, “OK”} default button 3
if button returned of result is “OK” then
set theWorkingName to text returned of result
else if button returned of result is “Switch” then
set theWorkingName to word 2 of theHandlersFileName & “_” & word 1 of theHandlersFileName
else if button returned of result is “Cancel” then
exit repeat
end if
end if
set AppleScript’s text item delimiters to prevAppleScriptdelimiters
ConstructtheNewFilingName(theWorkingName)
set theNewFilingName to result as text
my MovetheFiles(theNewFilingName, Target_Folder, theTruncatedFindingName)
display dialog “Done”
end tell
Child (handler):
on ConstructtheNewFilingName(theWorkingName)
tell application “Finder”
set theUpperString to “ABCDEFGHIJKLMNOPQRSTUVWXYZ”
set theLowerString to “abcdefghijklmnopqrstuvwxyz”
set prevAppleScriptdelimiters to AppleScript’s text item delimiters
set AppleScript’s text item delimiters to {“_”} --set the delimiter you like inside the quote marks
if ((count of text items of theWorkingName) is 3) then
set theGivenName to (text item 1 of theWorkingName)
set theMiddleName to (text item 2 of theWorkingName)
set theFamilyName to (text item 3 of theWorkingName)
else if ((count of text items of theWorkingName) is 2) then
set theGivenName to (text item 1 of theWorkingName)
set theMiddleName to {}
set theFamilyName to (text item 2 of theWorkingName)
else if ((count of text items of theWorkingName) is 1) then
set theGivenName to (text item 1 of theWorkingName)
set theMiddleName to {}
set theFamilyName to {}
end if
set AppleScript’s text item delimiters to prevAppleScriptdelimiters
set x to the offset of (character 1 of theGivenName) in theLowerString
if x is greater than 0 then
if the number of characters in theGivenName is greater than 2 then
set theGivenName to (character x of theUpperString) & (characters 2 thru end of theGivenName)
else
set theGivenName to (character x of theUpperString)
end if
end if
if theMiddleName is not {} then
set y to the offset of (character 1 of theMiddleName) in theLowerString
if y is greater than 0 then
if the number of characters in theMiddleName is greater than 2 then
set theMiddleName to " " & (character y of theUpperString) & (characters 2 thru end of theMiddleName)
else
set theMiddleName to " " & (character y of theUpperString)
end if
end if
end if
if theFamilyName is not {} then
set z to the offset of (character 1 of theFamilyName) in theLowerString
if z is greater than 0 then
if the number of characters in theFamilyName is greater than 2 then
set theFamilyName to (character z of theUpperString) & (characters 2 thru end of theFamilyName) & ", "
else
set theFamilyName to (character z of theUpperString) & ", "
end if
end if
end if
set theNewFilingName to theFamilyName & theGivenName & theMiddleName as string
end tell
return theNewFilingName
end ConstructtheNewFilingName
Results with parent returning the Log events:
ConstructtheNewFilingName(“Bucky_Edgett”)
“Finder got an error: Can’t continue ConstructtheNewFilingName.”
The Event Log gives no indication that the Finder actually tried to do any part of the handler. Is it not finding it? This is all copied more or less verbatim from OS 9 scripts, with some updating in the beginning of the parent for OS X. If I run it with the handler embedded in the Parent (using my ConstructtheNewFilingName) it does work perfectly, so I don’t think there’s a problem with the actual routine in the handler.
I’ve tried creating the simplest Parent/Child “tell app “Finder”/makebeep/end tell” and makebeep.scrpt, but the same thing happens: Finder can’t continue.
I’ve tried putting the handlers in various folders: Libraries, Scripting Additions, etc. No go!
What is the new proper OS X way to do this? Thanks so very much!