An automated PowerShell utility that switches to a specified audio output device after a period of user inactivity.
This script monitors your computer for inactivity and automatically switches to a designated audio device when you step away from your computer. When user activity is detected again, the script prepares to monitor for the next inactivity period.
Perfect for users who want to:
- Automatically switch from headphones to speakers when they step away
- Enforce audio routing policies based on activity state
- Switch to different audio devices based on idle time thresholds
- Automatically detects and installs required dependencies
- Monitors system for user inactivity (keyboard/mouse)
- Switches to a specified audio output device after customizable inactivity period
- Visual progress indicator showing time until audio switch
- Detailed console logging of state changes
- Easily configurable via command-line parameters
- Windows operating system
- PowerShell 5.1 or higher
- Internet connection (for first-time module installation)
- Administrative privileges (may be required for module installation)
- Save the script as
SwitchAudio.ps1
to your preferred location - The script will automatically install the required AudioDeviceCmdlets module on first run
Run the script with default parameters (switches to "Audio Out Rear" after 60 seconds of inactivity):
.\SwitchAudio.ps1
Specify a different target device and/or inactivity threshold:
.\SwitchAudio.ps1 -TargetDeviceName "Speakers" -InactivitySeconds 30
-TargetDeviceName
: The name of the audio device to switch to (partial matches work)-InactivitySeconds
: Number of seconds of inactivity before switching (default: 60)
If you encounter module installation issues:
- Run PowerShell as Administrator
- Execute:
Install-Module -Name AudioDeviceCmdlets -Force
- Try running the script again
If your target device isn't being detected:
- Run the script once to see the list of available devices
- Use the exact name listed in the output with the
-TargetDeviceName
parameter
The script:
- Checks for and installs the AudioDeviceCmdlets module if necessary
- Imports native Windows functions to detect user input activity
- Identifies available audio playback devices
- Monitors for user inactivity using a progress bar display
- Switches to the target device when the inactivity threshold is reached
- Resets when user activity is detected
This script is provided "as is" with no warranties. Use at your own risk.
- Uses the AudioDeviceCmdlets PowerShell module