macOS 右键菜单添加脚本
要点:在 自动操作软件中
- 新建快捷操作
- 工作流程输入: “文件和文件夹”
- 位于 访达
- 下面 传递输入 , 作为自变量
右键菜单展示
1.增加一个转换gbk - utf8的功能
for f in "$@"
do
iconv -f GBK -t UTF-8 "$f" > "${f%.txt}.utf8.txt"
done
🔸 iconv -f GBK -t UTF-8 "$f" > "${f%.txt}.utf8.txt"
iconv
是命令本体,执行编码转换:-f GBK
:原编码是 GBK-t UTF-8
:目标编码是 UTF-8
"$f"
是当前要处理的原始文件路径> "${f%.txt}.utf8.txt"
表示:- 输出文件为原文件名把
.txt
改为.utf8.txt
${f%.txt}
是 Bash 的字符串替换语法,意思是“把结尾的.txt
去掉”- 如果原文件叫
hello.txt
,那输出文件就是hello.utf8.txt
- 输出文件为原文件名把
>
表示输出写入新文件(不会覆盖原文件)
增加【用code 打开】菜单
https://code.visualstudio.com/ vscode, 程序员必备!
for f in "$@"
do
open -a "Visual Studio Code" "$f"
done
增加用 iterm 打开 菜单
https://iterm2.com/ 是一个很棒的终端软件。
for f in "$@"
do
open -a "iTerm" "$f"
done
增加用keka压缩菜单
这个需要使用 apple script 而不是命令行指令 keka 可以在 https://www.keka.io/en/ 下载,是一个开源好用的macos压缩软件。
on run {input, parameters}
repeat with f in input
set thePath to POSIX path of f
do shell script "open -a Keka \"" & thePath & "\""
end repeat
return input
end run