Skip to content

Instantly share code, notes, and snippets.

@FelDev
Last active August 7, 2021 12:21
Show Gist options
  • Select an option

  • Save FelDev/963910b1f2db11b46ef088e4c8da3d00 to your computer and use it in GitHub Desktop.

Select an option

Save FelDev/963910b1f2db11b46ef088e4c8da3d00 to your computer and use it in GitHub Desktop.
Random mac alert sound from Python
#!/usr/bin/env python3
import subprocess, random, glob
print('HERE WE GO')
sounds = glob.glob('/Users/{yourName}/Library/Sounds/*.aiff')
sound = random.choice(sounds)
print('randomly selected sound: ', sound)
command = 'defaults write .GlobalPreferences com.apple.sound.beep.sound /Users/{yourName}/Library/Sounds/{}.aiff'.format(sound)
# You could also define an array of sounds yourself, if you don't want every
# .aiff file to be a possibility
# sounds=['tabarnak1', 'tabarnak2', 'tabarnak3']
# sound=random.choice(sounds)
# command = 'defaults write .GlobalPreferences com.apple.sound.beep.sound /Users/{yourName}/Library/Sounds/{}.aiff'.format(sound)
subprocess.call(command, shell=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment