1

If one moves any file to the Trash folder on a Mac, by default, a short sound effect plays through the Mac's audio output (assuming that the system audio has not been muted).

I have an .scpt file where nothing is truly being moved to the Trash folder, but I would still like to have the Trash sound effect play.

I understand that I can download the sound effect onto my computer as an audio file from the Internet, and write:

do shell script "afplay /Users/Me/Desktop/TrashSoundEffect.aiff"

However, I would prefer to reference the built-in Trash sound effect. Is this possible?

I just don't like the idea of having to rely on an additional file to have my AppleScript function correctly. The built-in sound effect is more reliable, as it is guaranteed to remain on my computer indefinitely.

4

How about this one:

do shell script "afplay '/System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds/dock/drag to trash.aif'"

Update:

To address your comment, this is covered in Technical Note TN2065 - do shell script in AppleScript under Other Concerns where it says:

"... how do I make do shell script not wait until the command completes?"

Use do shell script \"command &> file_path &\". do shell script will return immediately with no result and your AppleScript script will be running in parallel with your shell script. The shell script’s output will go into file_path; if you don’t care about the output, use /dev/null.

Example:

do shell script "afplay '/System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds/dock/drag to trash.aif' &> /dev/null &"
  • It works nicely. I notice that the script is "paused" until the sound effect fully comes to an end. Do you know how to make the script move onto the next line as soon as your line is triggered? In other words, is it possible to have a without waiting for completion-type effect for the afplay command? – rubik's sphere May 6 '17 at 10:01
  • maybe a try block? [just a guess, I've never tested it.] – Tetsujin May 6 '17 at 11:43
  • @rubik's sphere, I've updated the answer to cover your comment. – user3439894 May 6 '17 at 15:09
  • @Tetsujin, A try statement block is not going to do anything towards what was asked by rubies' sphere in his comment. Please delete your comment, thanks. – user3439894 May 6 '17 at 15:11
  • @user3439894 With your updated answer, the script still waits until the audio file has fully played before moving on to the next line of code. I confirmed this by swapping out the short "drag to trash.aif" audio file with an audio file that has a length of 3 minutes, and the script was paused for 3 minutes. – rubik's sphere May 6 '17 at 20:30

You must log in to answer this question.

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