Skip to content

Instantly share code, notes, and snippets.

@mattorp
Created March 2, 2024 12:07
Show Gist options
  • Save mattorp/e88ea4d0f33dfb8e7aacda7283659df2 to your computer and use it in GitHub Desktop.
Save mattorp/e88ea4d0f33dfb8e7aacda7283659df2 to your computer and use it in GitHub Desktop.
Limit Bluesound sound level while ignoring specificed inputs. E.g. for analog and optical

Running a Bash script and setting environment variables can be done in a Unix-like environment, such as Linux or macOS. If you're using Windows, you'll need a tool like Git Bash, Windows Subsystem for Linux (WSL), or Cygwin to run Bash scripts.

Running the Script

  1. Save the Script: First, you need to save the script on your computer. Create a new file named limit-volume-bluos.sh and paste the script into this file.

  2. Make the Script Executable: Before running the script, you need to make it executable. Open a terminal, navigate to the directory where limit-volume-bluos.sh is saved, and run the following command:

chmod +x limit-volume-bluos.sh
  1. Run the Script: Now, you can run the script. If you're in the same directory as the script, you can run it by typing:
./limit-volume-bluos.sh -i YOUR_DEVICE_IP -t TIMEOUT -l VOLUME_LIMIT -s SKIP_INPUTS

Replace YOUR_DEVICE_IP with the IP address of your BluOS device, TIMEOUT with the desired timeout in milliseconds, VOLUME_LIMIT with the maximum volume level, and SKIP_INPUTS with a comma-separated list of inputs to skip.

Setting Environment Variables

Environment variables are a way to persist settings across terminal sessions and script invocations. To set the environment variables for this script, you can do the following:

  1. Open Your Profile File: This file is executed every time a new terminal session is started. For most Unix-like systems, this is usually .bashrc or .bash_profile in your home directory. Open this file with a text editor. For example:
nano ~/.bashrc
  1. Add Environment Variables: At the end of the file, add lines to set the environment variables. For example:
export BLUOS_IP="192.168.1.100"
export BLUOS_TIMEOUT="100"
export BLUOS_LIMIT="-55"
export BLUOS_SKIP_INPUTS="input0,optical"

Replace the values with those appropriate for your setup.

  1. Apply the Changes: For the changes to take effect, you either need to start a new terminal session or source your profile file in the current session:
source ~/.bashrc

After setting these environment variables, you can run the script (./limit-volume-bluos.sh) without needing to specify the options each time, as the script will automatically pick up the values from the environment variables.

Reusing the Script

Once the environment variables are set, you can reuse the script anytime simply by running ./limit-volume-bluos.sh in the terminal. It will use the environment variables as default settings, making it convenient to run the script without manually entering the details every time.

@mattorp
Copy link
Author

mattorp commented Mar 2, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment