Created
January 7, 2024 20:58
-
-
Save revblaze/2fb4bd604e0184330d7be590b48b721a to your computer and use it in GitHub Desktop.
Play macOS system sounds within your application environment. Working as of Sonoma (macOS 14).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AVFoundation | |
struct SoundUtility { | |
static func play(systemSound: SystemSound) { | |
if let sound = NSSound(contentsOfFile: systemSound.path, byReference: true) { | |
sound.play() | |
} else { | |
print("Failed to play system sound") | |
} | |
} | |
} | |
enum SystemSound { | |
case trash, poof, mount, unmount | |
var path: String { | |
switch self { | |
case .trash: return "/System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds/dock/drag to trash.aif" | |
case .poof: return "/System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds/dock/poof item off dock.aif" | |
case .mount: return "/System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds/system/Volume Mount.aif" | |
case .unmount: return "/System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds/system/Volume Mount.aif" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage