我正在尝试设置一个监视文件夹,以便当将文件添加到文件夹时,我可以运行 shell 脚本...为此我做了一个简单的测试但无法使其工作...
这是我的苹果脚本
on adding folder items to theWatchedFolder after receiving theDetectedItems
activate
display dialog "Transcode Successful"
do shell script "/Users/wme/Desktop/script.sh" & theDetectedItems
end adding folder items to
和 script.sh
#!/bin/sh
f="$1"
do
name=$(basename "$f")
dir=$(dirname "$f")
notify-send "$name"
done
虽然它确实提醒我“转码成功”,所以我知道 applescript 正在运行...但我没有通过 shellscript 收到已传输正确文件名的通知...我该怎么做呢?
答案1
on adding folder items to p after receiving input
set l to {}
repeat with f in input
set end of l to quoted form of POSIX path of f
end repeat
set text item delimiters to " "
do shell script "bash ~/Desktop/script.sh " & (l as text)
end adding folder items to
您还可以使用 Automator 创建直接运行 Shell 脚本的文件夹操作: