首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Applescript变量问题

Applescript变量问题
EN

Stack Overflow用户
提问于 2014-02-28 03:11:21
回答 2查看 181关注 0票数 0

当运行错误时,我对这个脚本有问题

代码语言:javascript
复制
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路径,以及如何对其进行更正。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-02-28 06:06:08

尝试:

代码语言:javascript
复制
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
票数 0
EN

Stack Overflow用户

发布于 2014-02-28 03:53:18

AppleScript很奇怪。music_file是由Finder应用程序定义的document file类型,而不是其他类型的file对象。如果您将其转换为带有aliasmusic_file as alias,那么您就可以得到它的POSIX path,这是命令行所需要的。最后,您需要在文件名周围包装另一组'字符,以防它包含空格。注意,如果文件名本身包含'字符,就会中断,就像在Crazy 'Cause I Believe.mp3中一样。

代码语言:javascript
复制
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)) & "'"
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22085446

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档