Opening a local .mp3 file with AppleScript Editor

applescriptmp3

So I have been trying to create an AppleScript application that when I click on it, it opens a mp3 file within the packages contents and resources. This is the only code I have within the script:

set filepath to (path to me as string) & "Contents:Resources:Jingle bells.mp3"

tell application "Finder"
    open alias filepath

but I receive a "script error" message saying:
error "Finder got an error: Can’t get alias \"Macintosh HD:Users:bobby.hay:Desktop:Song.app:Contents:Resources:Scripts:main.scptContents:Resources:Jingle bells.mp3\"." number -1728

I am trying to get the application to open Jingle bells.mp3 which is inside /Contents/Resources of my script.

Best Answer

Assuming that by "open" you mean play the mp3, the following script should do exactly what you want:

set myFolder to POSIX path of (path to me)
set contentFile to myFolder & "Contents/Resources/Jingle bells.mp3"
do shell script "afplay " & quoted form of contentFile

Above, we set myFolder to the POSIX path of .app file that is being run. Then we set contentFile to the POSIX path of the .app file plus the location in the internal directory which links to the file you want to play (Contents/Resources/Jingle bells.mp3 in your case). Finally, we use the shell command afplay (man page here) to play your mp3 file.

Hope this helps!

Best, Tom