繁体   English   中英

Applescript变量问题

[英]Applescript Variable issue

运行错误时此脚本出现问题

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_NARITA_HI_long_1.mp3”->错误“只能指定一个文件来播放,所以我尝试使用posix命令,例如如:

将conver设置为music_file的POSIX文件

然后那个错误

我无法弄清楚的是为什么当我告诉Music_file仅获取文件以及如何更正它时,为什么要在其中获取整个HFS路径。

AppleScript很奇怪。 music_file属于Finder应用程序定义的document file类型,而不是其他某种file对象。 如果您将其转换为一个aliasmusic_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)) & "'"

尝试:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM