Shell Applescript变量问题
当运行此脚本时,我遇到问题Shell Applescript变量问题,shell,variables,applescript,Shell,Variables,Applescript,当运行此脚本时,我遇到问题 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 这就是错误: 是否使用shell脚本afplay
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
这就是错误:
是否使用shell脚本afplay'/Volumes/Macintosh HD/ringtones/'Macintosh HD:ringtones:Zen_ag_成田_HI_long_1.mp3
->错误可能只指定一个要播放的文件
因此,我尝试使用posix命令,例如:
将conver设置为音乐文件的POSIX文件
那就错了
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
我不明白的是,当我告诉音乐文件只获取文件以及如何更正它时,为什么音乐文件会获取整个HFS路径。AppleScript很奇怪。音乐文件是Finder应用程序定义的文档文件类型,而不是其他类型的文件对象。如果将其转换为别名,并使用music_文件作为别名,则可以获得它的POSIX路径,这是命令行上所需的路径。最后,您需要在文件名周围包装另一组字符,以防它包含空格。请注意,如果文件名本身包含“characters,as in Crazy”,这将中断,因为我相信.mp3
尝试:
这是一个好的开始,我想做的就是从music_文件中抓取随机文件名,这是我想向Finder索要的。然后我就可以编写一个shell脚本来播放“Macintosh HD/music/”和music_文件,而不用担心文件名中的空格。我们有一个赢家,我感谢你们两位在这个问题上的意见。
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