Last active
July 6, 2018 07:13
-
-
Save jsvennevid/8540344 to your computer and use it in GitHub Desktop.
Volume control for crouton-based linux installations on chromebooks using PulseAudio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
## | |
## Volume control script for PulseAudio and crouton chromebooks | |
## | |
## https://github.com/dnschneid/crouton/wiki/Keyboard | |
## | |
## v1.0: Initial release | |
## v1.1: Simplified mute toggle | |
## v1.2: Fixed (harmless) error that occured when capping max volume | |
## | |
## Usage: | |
## volume down | |
## volume up | |
## volume mute | |
## | |
min_vol=0 | |
max_vol=65536 | |
vol_incr=4096 | |
function set_relative_volume { | |
volume=$(($1+$2)) | |
volume=$([ $volume -gt $(($max_vol)) ] && echo $max_vol || echo $volume) | |
volume=$([ $volume -lt $(($min_vol)) ] && echo $min_vol || echo $volume) | |
new_volume=$(printf "0x%x" $volume) | |
pactl set-sink-volume $3 $new_volume | |
} | |
sink="cras-sink" | |
volume=$(pacmd dump | grep "set-sink-volume $sink" | cut -d" " -f3) | |
case "$1" in | |
u*) | |
set_relative_volume $volume $vol_incr $sink | |
;; | |
d*) | |
set_relative_volume $volume -$vol_incr $sink | |
;; | |
m*) | |
pactl set-sink-mute $sink toggle | |
;; | |
esac |
There is an error:
File "volume", line 22
function set_relative_volume {
^
SyntaxError: invalid syntax
Any thoughts? Thanks!!
function set_relative_volume {
^
SyntaxError: invalid syntax
You saved the code as a py file and try to run it with python that's why the error.
Save it as volume.sh instead and run it with bash volume.sh
You can put this in the last row of the file so you will know if it runs or not.
echo "volume.sh script has finished"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hello, i'd like to be able to control volume with keyboard shortcuts on kde running 14.04 on my toshiba chromebook cb35. apparently, this is the script to use with crouton but i'm not sure how to implement it. do i just safe it as a file in my home directory and source it in .local?