Monday, December 19, 2016

Setting system volume on startup (Ubuntu)

This script sets system volume to 0% on Mon-Fri if the system boots up between 8AM to 7PM (so your laptop doesn't shout when you receive some notification).

Otherwise, sets the volume to 100% (when you are at home :D).

#!/usr/bin/perl -w

my ($hour, $wday) = (localtime(time))[2, 6];

open my $log_h, ">>", "/tmp/volume_script_log";

my $vol = ($wday>0 && $wday<6)?(($hour >= 8 && $hour <=19)?0:100):100;

print $log_h "Day of the week is $wday, hour is $hour, setting volume to $vol%\n"; close($log_h);

`amixer -D pulse sset Master $vol%`

For running on start :

Add an entry to crontab file :

#1 (Open crontab file)

crontab -e

#2 (Add this line)

@reboot perl /path/to/

No comments:

Post a Comment