如果我在 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
我究竟做错了什么?