首页 » 操作系统 » macOS » 正文

MacOS 让任意英文目录名显示为中文的 .workflow

发布者:站点默认
2023/02/27 浏览数(577) 分类:macOS MacOS 让任意英文目录名显示为中文的 .workflow已关闭评论

此脚本做了(假设提前选中了名为 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

用快捷键调用:

将以上代码保存为“将目录名称本地化”后“键盘 -> 快捷键 -> 通用:“将目录名称本地化” -> ^⌥⌘\”

关于本地化目录名称

点击返回顶部
  1. 留言
  2. 联系方式