3

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"
    activate
    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.

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

1 Answer 1

6

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

You can use afplay instead:

do shell script "afplay " & songpath 
2
  • 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
    Commented Mar 19, 2016 at 11:47
  • 1
    Try afplay -h in terminal to see the possible options
    – Koen.
    Commented Mar 19, 2016 at 11:56

You must log in to answer this question.

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