Coder Social home page Coder Social logo

Comments (2)

bookercodes avatar bookercodes commented on July 22, 2024

Sorry, I haven't used this script in a while and am unable to help :(

from dotfiles.

petrleocompel avatar petrleocompel commented on July 22, 2024

@mnissov It's pretty easy.
You need to chande that 5 line to this

my $sink=$ARGV[0];

Because in if statement 0 == false thats the reason why it died.
Also at the end is missing exit command.
So after 43 line we need to exit 0;

So in the end whole script will look like

#!/usr/bin/env perl 

## The sink we are interested in should be given as the 
## 1st argument to the script. (No die because 0 is allowed)
my $sink=$ARGV[0];

## If the script has been run with a second argument,
## that argument will be the volume threshold we are checking
my $volume_limit=$ARGV[1]||undef;

## Run the pactl command and save the output in 
## ther filehandle $fh
open(my $fh, '-|', 'pactl list sinks');

## Set the record separator to consecutive newlines (same as -000)
## this means we read the info for each sink as a single "line".
$/="\n\n";

## Go through the pactl output
while (<$fh>) {
    ## If this is the sink we are interested in
    if (/#$sink/) {
        ## Extract the current colume of this sink
        /Volume:.*?(\d+)%/;
        my $volume=$1;
        ## If the script has been run with a second argument,
        ## check whether the volume is above or below that
        if ($volume_limit) {
            ## If the volume os greater than or equal to the
            ## value passed, print "y"
            if ($volume >= $volume_limit) {
               print "y\n";
                exit 0;
            }
            else {
                print "n\n";
                exit 1;
            }
        }   
        ## Else, if the script has been run with just one argument,
        ## print the current volume + exit
        else {
            print "$volume%\n";
            exit 0;
        }
    }
}

Buala. Enjoy working volume 🙂

from dotfiles.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.