当运行错误时,我对这个脚本有问题
tell application "Finder"
set music_file to some file of the folder "Macintosh HD:ringtones"
end tell
set volume output volume 30
do shell script "afplay '/Volumes/Macintosh HD/ringtones/'" & music_file这是一个错误:do shell脚本"afplay‘/HD:ringtones:Zen_ag_NARITA_HI_long_1.mp3/Macintosh/ringtone/’Macintosh HD:ringtones:Zen_ag_NARITA_HI_long_1.mp3“-> error”可能只指定一个文件来播放,因此我尝试使用posix命令,如:
将conver设置为music_file的POSIX文件
那错误就消失了
我无法理解的是,当我告诉music_file只获取文件时,它为什么要获取整个HFS路径,以及如何对其进行更正。
发布于 2014-02-28 06:06:08
尝试:
set myFolder to "/Users/me/Desktop/test"
tell application "System Events" to set music_file to POSIX path of (some file of folder myFolder)
set volume output volume 30
do shell script "afplay " & quoted form of music_file发布于 2014-02-28 03:53:18
AppleScript很奇怪。music_file是由Finder应用程序定义的document file类型,而不是其他类型的file对象。如果您将其转换为带有alias的music_file as alias,那么您就可以得到它的POSIX path,这是命令行所需要的。最后,您需要在文件名周围包装另一组'字符,以防它包含空格。注意,如果文件名本身包含'字符,就会中断,就像在Crazy 'Cause I Believe.mp3中一样。
tell application "Finder"
set music_file to some file of the folder "ref:Users:andrew:Music:iTunes:iTunes Media:Ringtones"
end tell
set volume output volume 30
do shell script "afplay '" & (POSIX path of (music_file as alias)) & "'"https://stackoverflow.com/questions/22085446
复制相似问题