<?php
// mamp_beep.php
// Play beep sound
// RJM Programming
// February, 2026
// Thanks to https://www.google.com/search?q=php+play+a+system+sound+on+macos+via+applescript&sca_esv=15996710540eb279&rlz=1C5OZZY_en&sxsrf=ANbL-n6nQqTi0oYnLKiqoyxpeM0ilNevnw%3A1770515210946&ei=CuuHaa_AOcGywcsPv_yrmAU&ved=0ahUKEwiv7d6R48iSAxVBWXADHT_-ClMQ4dUDCBM&uact=5&oq=php+play+a+system+sound+on+macos+via+applescript&gs_lp=Egxnd3Mtd2l6LXNlcnAiMHBocCBwbGF5IGEgc3lzdGVtIHNvdW5kIG9uIG1hY29zIHZpYSBhcHBsZXNjcmlwdDIFECEYoAFIo1tQjwpYxFhwAXgAkAEAmAHrAaABxCWqAQYwLjI0LjK4AQPIAQD4AQGYAhqgAqglwgIKEAAYsAMY1gQYR8ICBRAhGJ8FwgIHECEYoAEYCpgDAIgGAZAGA5IHBjEuMjMuMqAHuXWyBwYwLjIzLjK4B5olwgcHMi4xMi4xMsgHS4AIAA&sclient=gws-wiz-serp

// AppleScript to play the default system beep sound once
$appleScript = 'beep';
if (isset($_GET['sound'])) {
  $appleScript=explode('"',str_replace('+',' ',urldecode($_GET['sound'])))[0];
}
if (isset($_POST['sound'])) {
  $appleScript=explode('"',str_replace('+',' ',urldecode($_POST['sound'])))[0];
}

if ($appleScript != '') {
  if (substr($appleScript,0,4) != 'beep') { 
     exec("afplay /System/Library/Sounds/" . strtoupper(substr($appleScript,0,1)) . strtolower(substr($appleScript,1)) . ".aiff");
     exit;
  }
}

// Execute the AppleScript using osascript
exec("osascript -e '{$appleScript}'");
?>