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.
-
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. -
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
- 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.
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:
- 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
- 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.
- 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.
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.
https://gist.github.com/mattorp/1eab74b0d137ec72ed8f4a63f7454261