下面是我重命名文件的代码。该代码基本上检查特殊字符并替换为"_"
(下划线)。
代码
set thefile to choose file
set Filename to my replace_chars(thefile, " ", " ")
set Filename to my replace_chars(thefile, " ", " ")
set Filename to my replace_chars(thefile, " ", "_")
set Filename to my replace_chars(thefile, ",", "_")
set Filename to my replace_chars(thefile, "!", "_")
set Filename to my replace_chars(thefile, "~", "_")
set Filename to my replace_chars(thefile, "*", "_")
set Filename to my replace_chars(thefile, "/", "_")
set Filename to my replace_chars(thefile, ":", "_")
set Filename to my replace_chars(thefile, "(", "_")
set Filename to my replace_chars(thefile, ")", "_")
set Filename to my replace_chars(thefile, "___", "_")
set Filename to my replace_chars(thefile, "__", "_")
tell application "Finder"
set the name of file thefile to "Testing.png"
end tell
on replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars
它抛出"Cant get every text item of alias"
请指教。