此脚本做了(假设提前选中了名为 projects 的目录):
0. 弹出输入框(假设你输入了“项目目录”并点了确定按钮) 1. 将 projects 改名为 projects.localized 2. 创建 projects.localized/.localized/zh_CN.strings 3. 在 zh_CN.strings 中写入 "projects"="项目目录";
AppleScript 脚本代码:
on run {input, parameters} -- 将目录名称本地化 tell application "Finder" -- 获取 Finder 选中的文件夹 set selected_folder to (get insertion location) set folder_name to name of folder (selected_folder as text) if folder_name does not end with ".localized" then set localized_name to text returned of (display dialog "本地化:" & folder_name default answer "") -- 创建 ./.localized/zh_CN.strings set newfolder to make new folder at (get insertion location) with properties {name:".localized"} set newfile to make new file at newfolder with properties {name:"zh_CN.strings", file type:"TEXT"} -- 在 ./.localized/zh_CN.strings 中写入内容 set localized_text to "\"" & folder_name & "\"=\"" & localized_name & "\";" set the target_file to the newfile as text write localized_text to file target_file starting at eof as «class utf8» -- 将父目录改名为 *.localized(先改名后边的脚本就找不到父目录了) set name of selected_folder to ((name of selected_folder) & ".localized") else display alert folder_name & " has localized" end if end tell return input end run
用快捷键调用:
将以上代码保存为“将目录名称本地化”后“键盘 -> 快捷键 -> 通用:“将目录名称本地化” -> ^⌥⌘\”