I am having issues with this script when run it errors out
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
this is the error: do shell script "afplay '/Volumes/Macintosh HD/ringtones/'Macintosh HD:ringtones:Zen_ag_NARITA_HI_long_1.mp3" --> error "may only specify one file to play so I attempted to use a posix command such as:
set conver to POSIX file of music_file
and that errors out
What I cannot figure out is why the music_file is getting the whole HFS path in it when I tell it to just get the file and how to correct for it.
AppleScript is weird. music_file
is of type document file
as defined by the Finder
app, instead of being some other kind of file
object. If you convert it to an alias
with music_file as alias
, then you can get the POSIX path
of it which is what's needed on the command line. Finally you need to wrap another set of '
characters around the filename in case it includes spaces. Note that this will break if the filename itself contains '
characters, as in 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)) & "'"
Try:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.