LoginSignup
5
4

More than 5 years have passed since last update.

Mac でシステムで用意されているサウンドをランダムに再生する

Posted at
$ afplay -v 2 $(find /System/Library/Sounds -type f -maxdepth 1 | gshuf | sed -n "1p")

上記を実行すると

  • /System/Library/Sounds/Basso.aiff
  • /System/Library/Sounds/Blow.aiff
  • /System/Library/Sounds/Bottle.aiff
  • /System/Library/Sounds/Frog.aiff
  • /System/Library/Sounds/Funk.aiff
  • /System/Library/Sounds/Glass.aiff
  • /System/Library/Sounds/Hero.aiff
  • /System/Library/Sounds/Morse.aiff
  • /System/Library/Sounds/Ping.aiff
  • /System/Library/Sounds/Pop.aiff
  • /System/Library/Sounds/Purr.aiff
  • /System/Library/Sounds/Sosumi.aiff
  • /System/Library/Sounds/Submarine.aiff
  • /System/Library/Sounds/Tink.aiff

のいずれかがランダムで再生されます

分解する

任意の音声ファイルを再生する

$ afplay some.mp3

乱数を取得

※ gshuf を使う場合は brew install coreutils しておくこと

$  seq 10 | gshuf
7
6
5
3
8
10
9
1
2
4

先頭1行を取得する

$ seq 10 | sed -n '1p'
1

補足

とくにShellに詳しいわけではないのでよりよいかき方があるかも

関連資料

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4