![通过 shell 脚本强制清空 macOS 上的垃圾箱](https://linux22.com/image/188128/%E9%80%9A%E8%BF%87%20shell%20%E8%84%9A%E6%9C%AC%E5%BC%BA%E5%88%B6%E6%B8%85%E7%A9%BA%20macOS%20%E4%B8%8A%E7%9A%84%E5%9E%83%E5%9C%BE%E7%AE%B1.png)
如果我在 macOS (11.2.1) 终端中运行此命令:
sudo rm -rf ~/.Trash/*
...在系统对话框中输入我的 Mac 密码后,垃圾箱被成功强制清空。
但是,如果我尝试从此脚本文件强制清空垃圾箱,系统对话框将显示正常,并且通知按预期工作,但垃圾箱不会被强制清空:
#!/bin/bash
if osascript -e "do shell script \"sudo rm -rf ~/.Trash/*\" with administrator privileges";
then
osascript -e "display notification \"Trash was forced empty.\" with title \"OK\""
else
osascript -e "display notification \"Trash was NOT forced empty!\" with title \"ERROR\""
fi
我究竟做错了什么?