The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Script to mute_unmute system

Here’s a simple cross-platform script to mute and unmute your system volume. Choose the version based on your operating system.


Windows (using PowerShell)

powershell
# Toggle mute/unmute system volume on Windows Add-Type -TypeDefinition @" using System.Runtime.InteropServices; public class Sound { [DllImport("user32.dll")] public static extern int SendMessageA(IntPtr hWnd, int Msg, int wParam, int lParam); } "@ # 0x319 = WM_APPCOMMAND, 0x80000 = APPCOMMAND_VOLUME_MUTE [void][Sound]::SendMessageA(-1, 0x319, 0x80000, 0x80000)

Save as toggleMute.ps1 and run using PowerShell:

powershell
powershell -ExecutionPolicy Bypass -File toggleMute.ps1

macOS (using AppleScript in Terminal)

bash
# Toggle mute/unmute on macOS osascript -e 'set volume output muted not (output muted of (get volume settings))'

Linux (using amixer)

Install alsa-utils if not already installed.

bash
# Toggle mute/unmute on Linux (for default output) amixer -D pulse set Master toggle

If you want the script in a specific programming language like Python or a GUI button, let me know and I’ll provide that version.

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About