The 1st dialog box displays with the name of the file, but the 2nd one doesn’t.
It looks like the function doesn’t even get called.
on adding folder items to this_folder after receiving added_items
try
tell application "Finder"
set parent_folder to the parent of this_folder as string
set out_folder to parent_folder & "Out" as string
set processed_folder to parent_folder & "Processed" as string
repeat with current_item in added_items
set current_item_name to the name of current_item as string
display dialog current_item_name
display dialog stripExtension(current_item_name)
end repeat
end tell
end try
end adding folder items to
on stripExtension(current_item_name)
set delim to AppleScript's text item delimiters
set AppleScript's text item delimiters to "."
set clean_name to (text items 1 through -2 of (current_item_name as string) as list) as string
set AppleScript's text item delimiters to delim
return clean_name
end stripExtension
while developing scripts try blocks without error handling are disadvantageous, because you never get an error message.
The problem is that a handler call within an application tell block throws an “Can’t continue” error.
Put the keyword my in front if the handler call
display dialog my stripExtension(current_item_name)
or (preferable) use a tell block only for lines with appropriate application terminology
I removed all useless as string coercions and the try block, which doesn’t work in a folder action event anyway.
on adding folder items to this_folder after receiving added_items
tell application "Finder" to set parent_folder to the container of this_folder as text
set out_folder to parent_folder & "Out"
set processed_folder to parent_folder & "Processed"
repeat with current_item in added_items
tell application "Finder" to set current_item_name to the name of current_item
display dialog current_item_name
display dialog stripExtension(current_item_name)
end repeat
end adding folder items to
on stripExtension(current_item_name)
set delim to AppleScript's text item delimiters
set AppleScript's text item delimiters to "."
set clean_name to (text items 1 through -2 of current_item_name) as text
set AppleScript's text item delimiters to delim
return clean_name
end stripExtension
Note: parent is an undocumented command, better use container
It’s a bit of a step moving my scripts from VB to Applescript.
This is my final script, except that file names with spaces aren’t getting output. I read somewhere that shell scripts needs spaces to be escaped\ out. But I also read somewhere that quoted form of should fix that; but it doesn’t work.
on adding folder items to this_folder after receiving added_items
tell application "Finder" to set parent_folder to the container of this_folder as text
set out_folder to parent_folder & "Out"
set processed_folder to parent_folder & "Processed"
repeat with current_item in added_items
tell application "Finder" to set current_item_name to the name of current_item
set shell_command to "PATH=$PATH:/usr/local/bin; autogamma " & quoted form of (POSIX path of current_item) & " " & quoted form of (POSIX path of processed_folder & "/" & my stripExtension(current_item_name) & ".tif")
do shell script shell_command
end repeat
end adding folder items to
on stripExtension(current_item_name)
set delim to AppleScript's text item delimiters
set AppleScript's text item delimiters to "."
set clean_name to (text items 1 through -2 of (current_item_name as string) as list) as string
set AppleScript's text item delimiters to delim
return clean_name
end stripExtension
.
set shell_command to "usr/local/bin/autogamma " & quoted form of (POSIX path of current_item) & " " & quoted form of (POSIX path of processed_folder & "/" & my stripExtension(current_item_name) & ".tif")
.