Flexible Volume Controller AppleScript

This AppleScript lets you adjust your Mac’s system volume either by selecting from a list of predefined levels (Mute, 0, 25, 50, 75, or 100) or by entering a custom value between 0 and 100, with a notification confirming the change.

Click to view script…
-- Volume Controller Script

-- First, choose the control method.
display dialog "Choose Volume Control Method:" buttons {"Predefined Levels", "Custom Level"} default button "Predefined Levels"
set methodChoice to button returned of result

if methodChoice is "Predefined Levels" then
    -- Use a list to display multiple predefined options.
    set volumeOptions to {"Mute", "0", "25", "50", "75", "100"}
    set volChoiceList to choose from list volumeOptions with prompt "Select Volume Setting:" default items {"50"}
    
    if volChoiceList is false then
        display notification "No selection made." with title "Volume Controller"
        return
    end if
    
    set volChoice to item 1 of volChoiceList
    if volChoice is "Mute" then
        set volume with output muted
        display notification "Volume muted" with title "Volume Controller"
    else
        set volValue to volChoice as integer
        set volume output volume volValue
        display notification "Volume set to " & volValue & "%" with title "Volume Controller"
    end if
    
else if methodChoice is "Custom Level" then
    display dialog "Enter desired volume level (0-100):" default answer "50"
    set volInput to text returned of result
    set volLevel to volInput as integer
    
    if volLevel < 0 then
        set volLevel to 0
    else if volLevel > 100 then
        set volLevel to 100
    end if
    
    set volume output volume volLevel
    display notification "Volume set to " & volLevel & "%" with title "Volume Controller"
end if