
基於這篇文章如何從命令列將文件新增到 iTunes,而不播放該文件這有效我想添加多個文件而不是一個。
我嘗試添加循環和查找:
for f in ./*.m4a; do osascript -e \
"tell application \"iTunes\" to add "$f" Posix file; done
# Or...
find /Users/filedirectory\
-type f -name "*.m4a" \
-osascript -e "tell application \"iTunes\" to add Posix file {}; done
終端給出>
沒有錯誤。
答案1
AppleScript 要求 POSIX 路徑必須加引號,且 iTunes 的路徑必須是完整路徑名稱。
對於 shellfor
命令,路徑必須是完整路徑,因此使用pwd
.$f
必須引用:
for f in "`pwd`"/*.m4a; do osascript -e \
"tell application \"iTunes\" to add Posix file \"$f\""; done
對於find
版本(最後沒有“完成”),引用如下{}
:
find /Users/filedirectory \
-type f -name "*.m4a" \
-exec osascript -e "tell application \"iTunes\" to add Posix file \"{}\"" \;
用於pwd
定位目前目錄中的檔案。之後pwd
,其餘命令是相同的。
find "`pwd`" -type f ...
新增到 iTunes 的每個檔案都會顯示如下行:
file track id 142123 of library playlist id 25858 of source id 65