I'm trying to make an app that when opened will play an audio file that is contained in the app, but i have no idea how to do it. I know this is really vague and I apologize but any help would be awesome.

This other question covers high level how to make an app, but I can't figure how to actually make the shell.

Is there a guide or sample code to show how to take an actual file and actually play it in AppleScript framework?


Here is an example of one way to achieve your goal:

In Script Editor, I used the following three lines of code and saved it as an application, as Hello World.app:

set resourceName to "Hello World.aiff"

set filePathName to quoted form of POSIX path of (path to resource resourceName) as text

do shell script "afplay " & filePathName

Then inside the application bundle in the Resources folder, I placed the audio file Hello World.aiff, which is a file of someone saying "hello world".

Here is a tree view of the hierarchal structure of the application bundle:

Hello World.app
└── Contents
    ├── Info.plist
    ├── MacOS
    │   └── applet
    ├── PkgInfo
    └── Resources
        ├── Hello World.aiff
        ├── Scripts
        │   └── main.scpt
        ├── applet.icns
        ├── applet.rsrc
        └── description.rtfd
            └── TXT.rtf

Now when I double-click on the Hello World.app is plays the Hello World.aiff audio file.


After you create the application bundle, then in Finder you right-click on it selecting Show Package Contents and then navigate to the Resources folder where you'll place your audio file.

Change the name of the resourceName from "Hello World.aiff", to whatever your audio file name is, in the example code so it will work for your filename.


You must log in to answer this question.

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