I put together a script that goes into a folder and names the images inside based on the folders those images are in.
I would like to make it a finder service so I can right click a folder to use it.
(I've done these before, so I know, in theory, how to do it)
When I try to use it, or more to the point, Compile the applescript in it, I get a Syntax Error: Expected end but found to.
The "to" is the subroutine of the script...so does Automater/Services not know how to do use it? (Again, the Script itself works fine.)
Anyone have ideas or help in this?
THE ORIGINAL SCRIPT:
THE SCRIPT MODIFIED FOR THE SERVICE:
I would like to make it a finder service so I can right click a folder to use it.
(I've done these before, so I know, in theory, how to do it)
When I try to use it, or more to the point, Compile the applescript in it, I get a Syntax Error: Expected end but found to.
The "to" is the subroutine of the script...so does Automater/Services not know how to do use it? (Again, the Script itself works fine.)
Anyone have ideas or help in this?
THE ORIGINAL SCRIPT:
Code:
(* This is an applescript that takes images in a folder and renames them based on the name of the folder. It will transverse thru subfolders and do the same.*)
set all_files to {}
set filelist to {}
set foldlist to {}
set ImgExtension to {"jpg", "psd", "gif", "png"}
tell application "Finder"
set mifold to choose folder
try
set filelist to (every file of mifold where name extension is in ImgExtension)
set foldlist to every folder of mifold #as list
end try
if foldlist is not {} then
repeat with eachFolder in foldlist
--set Base_Name to my MakeBase(eachFolder as string)
set count_er to 1
set all_files to (get every document file in eachFolder where name extension is in ImgExtension)
set finalNamePrefix to (name of (eachFolder) & "_")
repeat with thisFile in all_files
--set thisFile's name to (Base_Name & (text -3 thru -1 of ("000" & (count_er as string))) & "." & (thisFile's name extension))
set thisFile's name to (finalNamePrefix & (text -3 thru -1 of ("000" & (count_er as string))) & "." & (thisFile's name extension))
set count_er to count_er + 1
end repeat
end repeat
end if
if filelist is not {} then
set count_er to 1
#set all_files to (get every document file in eachFolder)
set finalNamePrefix to (name of (mifold) & "_")
repeat with thisFile in filelist
--set thisFile's name to (Base_Name & (text -3 thru -1 of ("000" & (count_er as string))) & "." & (thisFile's name extension))
set thisFile's name to (finalNamePrefix & (text -3 thru -1 of ("000" & (count_er as string))) & "." & (thisFile's name extension))
set count_er to count_er + 1
end repeat
end if
beep 3
end tell
to MakeBase(txt)
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set new_Name_Raw to every text item of txt
set AppleScript's text item delimiters to "_"
set final_Name to every text item of new_Name_Raw as text
set AppleScript's text item delimiters to astid
return final_Name
end MakeBase
THE SCRIPT MODIFIED FOR THE SERVICE:
Code:
on run {input, parameters}
set all_files to {}
set filelist to {}
set foldlist to {}
set ImgExtension to {"jpg", "psd", "gif", "png"}
tell application "Finder"
set mifold to input
try
set filelist to (every file of mifold where name extension is in ImgExtension)
set foldlist to every folder of mifold #as list
end try
if foldlist is not {} then
repeat with eachFolder in foldlist
--set Base_Name to my MakeBase(eachFolder as string)
set count_er to 1
set all_files to (get every document file in eachFolder where name extension is in ImgExtension)
set finalNamePrefix to (name of (eachFolder) & "_")
repeat with thisFile in all_files
--set thisFile's name to (Base_Name & (text -3 thru -1 of ("000" & (count_er as string))) & "." & (thisFile's name extension))
set thisFile's name to (finalNamePrefix & (text -3 thru -1 of ("000" & (count_er as string))) & "." & (thisFile's name extension))
set count_er to count_er + 1
end repeat
end repeat
end if
if filelist is not {} then
set count_er to 1
#set all_files to (get every document file in eachFolder)
set finalNamePrefix to (name of (mifold) & "_")
repeat with thisFile in filelist
--set thisFile's name to (Base_Name & (text -3 thru -1 of ("000" & (count_er as string))) & "." & (thisFile's name extension))
set thisFile's name to (finalNamePrefix & (text -3 thru -1 of ("000" & (count_er as string))) & "." & (thisFile's name extension))
set count_er to count_er + 1
end repeat
end if
beep 3
end tell
to MakeBase(txt)
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set new_Name_Raw to every text item of txt
set AppleScript's text item delimiters to "_"
set final_Name to every text item of new_Name_Raw as text
set AppleScript's text item delimiters to astid
return final_Name
end MakeBase
end run