0

I've created a bash script to play some music using the afplay command. I used the file extension .command so that it can be opened with a double click in finder. This is an abbreviation of the code.

#! /bin/bash

afplay playlist/01.m4a

The script works when I manually run it through terminal, but when I open the .command file through finder all I get is,

admins-iMac:~ user$ /Users/admin/Documents/bash/music.command ; exit;
Unspecified exception
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.

[Process completed]

And no music is played. Any help would be appreciated.

  • What's displayed if you modify your script to first do `echo $PWD` and `echo $PATH` ? – racraman Sep 09 '19 at 05:03
  • `admins-iMac:~ user$ /Users/admin/Documents/bash/music.command ; exit; Unspecified exception /Users/admin /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin logout Saving session... ...copying shared history... ...saving history...truncating history files... ...completed. [Process completed]` – Jakeman90210 Sep 09 '19 at 05:14
  • What is the full path of your playlist directory - is it actually in `/Users/admin`, or some lower level subdirectory ? If the latter, I'm wondering if try putting the full path in the script, something like "afplay /Users/admin/Documents/whatever/playlist/01.m4a` – racraman Sep 09 '19 at 05:34
  • The error is thrown by `afplay` executable. I think why `afplay` is throwing the error is out of scope for [so]. You'd get better results on [su]. If `afplay` has options like `--verbose`/`--debug` you might want to pass those options to it for better understanding of the issue. Also, try running the `afplay playlist/01.m4a` command directly from the terminal, instead of adding `;exit` after it. No point in exiting the terminal, if the command is failing anyway. – anishsane Sep 09 '19 at 05:50
  • Ah, it worked when I put the full file path. Thanks for the help. – Jakeman90210 Sep 09 '19 at 06:10
  • I'm getting apparently random Unspecified Result errors using combinations of 'afplay', '/usr/bin/afplay' as the program name and 'file.WAV' '/Volumes/ExternalHD/dir1/dir2/file.WAV' as the sound file, conducting tests over a period of 5-10 minutes. To add to the fun, when I call afplay from a shell script it fails more often than the identical call from the command line. My conclusion is that there is another process or system state that is interfering with afplay. – nortally Aug 09 '20 at 00:31

1 Answers1

0

No clue why but: afplay my played fine while mv my{,.mp3} && afplay my.mp3 won't and will exit with "Unspecified exception"

childno͡.de
  • 4,679
  • 4
  • 31
  • 57