Mac automator bash 自动操作 右键菜单unrar解压 拷贝文件路径到剪贴板 快速删除(rm -rf) 快捷键设置
https://tecadmin.net/pass-command-line-arguments-in-shell-script/
https://tecadmin.net/tutorial/bash-scripting/bash-command-arguments/
https://www.quora.com/Where-do-I-find-the-trash-sound-the-sound-when-you-empty-the-trash-in-Mac
默认当前路径是 ~
传递输入设置为 作为自变量
unrar 解压:
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
for i in "$@"
do
f=$i
path=$(dirname "$i")
/usr/local/bin/unrar x "$f" "$path"
done
复制文件路径:
# 这两句设置编码格式为 utf8,不然 pbcopy 复制中文路径时有问题
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
for f in "$@"
do
echo "$f" | tr -d '\r\n' | pbcopy
done
快速删除:
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
# 给个弹框提示
x=`osascript -e '
on run argv
set strTitle to "ARE YOU SURE"
set strContent to "rm -rf\n" & convertListToString(argv, "\n") & " ?"
set btns to {"NO", "YES"}
display dialog strContent with title strTitle buttons btns default button 2 cancel button 1 with icon caution
get the button returned of the result
end
on convertListToString(theList, theDelimiter)
set saveTID to text item delimiters
set text item delimiters to theDelimiter
set theString to theList as text
set text item delimiters to saveTID
return theString
end convertListToString
' $@`
if [[ $x = "YES" ]]; then
for f in "$@"
do
rm -rf "$f"
done
afplay /System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds/finder/empty\ trash.aif
fi
最后设置快捷键:
automator 的 bash 环境:
参考链接
Anything run from the Finder or elsewhere in the Aqua user interface knows nothing about your command line environment. There are some hacks you can do, but it is better to make your script stand-alone. If you need a particular environment, write a wrapper around it that sets up said environment and call that wrapper.
查看所有的环境变量:export -p
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
2018-12-02 three.js 一幅图片多个精灵