Okay so I want an applescript app that plays a song. The song isn't already on the computer and it's contained inside contents/resources of the app's package contents. This is my current code

tell application "Finder"
    set apppath to POSIX path of (application file id "com.apple.ScriptEditor.id.play" as text)
end tell
set song to {apppath, "/Contents/Resources/song.mp3"} as string
set songpath to POSIX file song as text
tell application "QuickTime Player"
    open songpath
    play the front document
    tell application "System Events"
        set visible of application process "QuickTime Player" to false
    end tell
end tell

On my computer this code seems to work. However when distributing it, other computers get an error in quicktime. The document “song.mp3” could not be opened. The file doesn’t exist. Any help?

Edit: Fixed an incorrect variable which doesn't fix the problem because I changed the code to post it here and mixed it up.

  • 1
    Where does QSpath come from?
    – Tetsujin
    Mar 16 '16 at 7:53
  • 1
    It would seem i have put the wrong variable in... anyway thanks for notifying me
    – cjeccjec
    Mar 19 '16 at 11:26

Activating QuickTime is a lot of overhead for playing a single file.

You can use afplay instead:

do shell script "afplay " & songpath 
  • Works like a charm. The only problem now would be controlling the audio. However that doesn't seem like something google can't help me with.
    – cjeccjec
    Mar 19 '16 at 11:47
  • 1
    Try afplay -h in terminal to see the possible options
    – Koen.
    Mar 19 '16 at 11:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .