Create a system alert beep on a Mac

Just starting out? Need help? Post your questions and find answers here.
JP-NYC
New User
New User
Posts: 2
Joined: Mon Dec 02, 2019 9:43 pm

Create a system alert beep on a Mac

Post by JP-NYC »

Is there an easier way to create the default system alert sound on a Mac without having to read the setting file to see what sound file it is set to, load the sound and then play the sound?

Thanks
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Create a system alert beep on a Mac

Post by wilbert »

You mean a beep like this ?

Code: Select all

OpenWindow(0, 0, 0, 222, 200, "Beep example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(0, 10, 10, 200, 40, "Beep")
Repeat
  Event = WaitWindowEvent()
  If Event = #PB_Event_Gadget And EventGadget() = 0
    NSBeep_()
  EndIf
Until Event = #PB_Event_CloseWindow
or

Code: Select all

#kUserPreferredAlert = $00001000

ImportC "-framework AudioToolbox"
  AudioServicesPlaySystemSound(SystemSoundID.l)
EndImport

OpenWindow(0, 0, 0, 222, 200, "User alert example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(0, 10, 10, 200, 40, "Alert")
Repeat
  Event = WaitWindowEvent()
  If Event = #PB_Event_Gadget And EventGadget() = 0
    AudioServicesPlaySystemSound(#kUserPreferredAlert)
  EndIf
Until Event = #PB_Event_CloseWindow
Windows (x64)
Raspberry Pi OS (Arm64)
JP-NYC
New User
New User
Posts: 2
Joined: Mon Dec 02, 2019 9:43 pm

Re: Create a system alert beep on a Mac

Post by JP-NYC »

Perfect. Thank you
Post Reply