YouTube pausing script works from command line, but not from shortcut

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








up vote
0
down vote

favorite












I wanted to pause YouTube and tried the last approach here using kill -SIGSTOP [pid]. Now the script works fine in the terminal but it doesn't work when invoked using a keyboard shortcut. The script:



#!/bin/sh
if [ -f /tmp/TimChromepid.RUN ]; then
mv /tmp/TimChromepid.RUN /tmp/TimChromepid.PSD
NMR=$(< /tmp/TimChromepid.PSD)
kill -SIGSTOP < /tmp/TimChromepid.PSD
else
NMR=$(< /tmp/TimChromepid.PSD)
mv /tmp/TimChromepid.PSD /tmp/TimChromepid.RUN
kill -SIGCONT $NMR
fi


I used the variable 'NMR' to store the PID, for when I feed it directly into kill I get this error:



kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]


As far as I can test it seems that it can run the script, and the if-statement, but it can't read the number from file nor can it execute kill.



How can I fix this and what's going on?







share|improve this question






















  • Your kill -SIGSTOP < /tmp/TimChromepid.PSD suggests that kill reads a PID from stdin — which it doesn't, thus the usage message. Try kill -SIGSTOP $(cat /tmp/TimChromepid.PSD) instead.
    – PerlDuck
    May 15 at 9:59










  • @Mark Have you tried adding bash in front of the script name to provide a shell when registering the keyboard shortcut?
    – dsstorefile1
    May 15 at 11:31







  • 1




    @dsstorefile1 Yes, that did it, thank you! :)
    – Mark
    May 16 at 7:35










  • Did you fix the shebang? Please edit your question and change the code accordingly. To read the PID from the file you can do kill -SIGSPEC $(</tmp/TimChromepid.PSD) or use cat as shown by @PerlDuck. Please add some echo lines to test and redirect the whole output to a log file, especially that of kill with &>/path/to/logfile, then provide the content of the log file.
    – dessert
    May 16 at 7:59














up vote
0
down vote

favorite












I wanted to pause YouTube and tried the last approach here using kill -SIGSTOP [pid]. Now the script works fine in the terminal but it doesn't work when invoked using a keyboard shortcut. The script:



#!/bin/sh
if [ -f /tmp/TimChromepid.RUN ]; then
mv /tmp/TimChromepid.RUN /tmp/TimChromepid.PSD
NMR=$(< /tmp/TimChromepid.PSD)
kill -SIGSTOP < /tmp/TimChromepid.PSD
else
NMR=$(< /tmp/TimChromepid.PSD)
mv /tmp/TimChromepid.PSD /tmp/TimChromepid.RUN
kill -SIGCONT $NMR
fi


I used the variable 'NMR' to store the PID, for when I feed it directly into kill I get this error:



kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]


As far as I can test it seems that it can run the script, and the if-statement, but it can't read the number from file nor can it execute kill.



How can I fix this and what's going on?







share|improve this question






















  • Your kill -SIGSTOP < /tmp/TimChromepid.PSD suggests that kill reads a PID from stdin — which it doesn't, thus the usage message. Try kill -SIGSTOP $(cat /tmp/TimChromepid.PSD) instead.
    – PerlDuck
    May 15 at 9:59










  • @Mark Have you tried adding bash in front of the script name to provide a shell when registering the keyboard shortcut?
    – dsstorefile1
    May 15 at 11:31







  • 1




    @dsstorefile1 Yes, that did it, thank you! :)
    – Mark
    May 16 at 7:35










  • Did you fix the shebang? Please edit your question and change the code accordingly. To read the PID from the file you can do kill -SIGSPEC $(</tmp/TimChromepid.PSD) or use cat as shown by @PerlDuck. Please add some echo lines to test and redirect the whole output to a log file, especially that of kill with &>/path/to/logfile, then provide the content of the log file.
    – dessert
    May 16 at 7:59












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I wanted to pause YouTube and tried the last approach here using kill -SIGSTOP [pid]. Now the script works fine in the terminal but it doesn't work when invoked using a keyboard shortcut. The script:



#!/bin/sh
if [ -f /tmp/TimChromepid.RUN ]; then
mv /tmp/TimChromepid.RUN /tmp/TimChromepid.PSD
NMR=$(< /tmp/TimChromepid.PSD)
kill -SIGSTOP < /tmp/TimChromepid.PSD
else
NMR=$(< /tmp/TimChromepid.PSD)
mv /tmp/TimChromepid.PSD /tmp/TimChromepid.RUN
kill -SIGCONT $NMR
fi


I used the variable 'NMR' to store the PID, for when I feed it directly into kill I get this error:



kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]


As far as I can test it seems that it can run the script, and the if-statement, but it can't read the number from file nor can it execute kill.



How can I fix this and what's going on?







share|improve this question














I wanted to pause YouTube and tried the last approach here using kill -SIGSTOP [pid]. Now the script works fine in the terminal but it doesn't work when invoked using a keyboard shortcut. The script:



#!/bin/sh
if [ -f /tmp/TimChromepid.RUN ]; then
mv /tmp/TimChromepid.RUN /tmp/TimChromepid.PSD
NMR=$(< /tmp/TimChromepid.PSD)
kill -SIGSTOP < /tmp/TimChromepid.PSD
else
NMR=$(< /tmp/TimChromepid.PSD)
mv /tmp/TimChromepid.PSD /tmp/TimChromepid.RUN
kill -SIGCONT $NMR
fi


I used the variable 'NMR' to store the PID, for when I feed it directly into kill I get this error:



kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]


As far as I can test it seems that it can run the script, and the if-statement, but it can't read the number from file nor can it execute kill.



How can I fix this and what's going on?









share|improve this question













share|improve this question




share|improve this question








edited May 21 at 9:22









Zanna

47.9k13118227




47.9k13118227










asked May 15 at 8:40









Mark

41




41











  • Your kill -SIGSTOP < /tmp/TimChromepid.PSD suggests that kill reads a PID from stdin — which it doesn't, thus the usage message. Try kill -SIGSTOP $(cat /tmp/TimChromepid.PSD) instead.
    – PerlDuck
    May 15 at 9:59










  • @Mark Have you tried adding bash in front of the script name to provide a shell when registering the keyboard shortcut?
    – dsstorefile1
    May 15 at 11:31







  • 1




    @dsstorefile1 Yes, that did it, thank you! :)
    – Mark
    May 16 at 7:35










  • Did you fix the shebang? Please edit your question and change the code accordingly. To read the PID from the file you can do kill -SIGSPEC $(</tmp/TimChromepid.PSD) or use cat as shown by @PerlDuck. Please add some echo lines to test and redirect the whole output to a log file, especially that of kill with &>/path/to/logfile, then provide the content of the log file.
    – dessert
    May 16 at 7:59
















  • Your kill -SIGSTOP < /tmp/TimChromepid.PSD suggests that kill reads a PID from stdin — which it doesn't, thus the usage message. Try kill -SIGSTOP $(cat /tmp/TimChromepid.PSD) instead.
    – PerlDuck
    May 15 at 9:59










  • @Mark Have you tried adding bash in front of the script name to provide a shell when registering the keyboard shortcut?
    – dsstorefile1
    May 15 at 11:31







  • 1




    @dsstorefile1 Yes, that did it, thank you! :)
    – Mark
    May 16 at 7:35










  • Did you fix the shebang? Please edit your question and change the code accordingly. To read the PID from the file you can do kill -SIGSPEC $(</tmp/TimChromepid.PSD) or use cat as shown by @PerlDuck. Please add some echo lines to test and redirect the whole output to a log file, especially that of kill with &>/path/to/logfile, then provide the content of the log file.
    – dessert
    May 16 at 7:59















Your kill -SIGSTOP < /tmp/TimChromepid.PSD suggests that kill reads a PID from stdin — which it doesn't, thus the usage message. Try kill -SIGSTOP $(cat /tmp/TimChromepid.PSD) instead.
– PerlDuck
May 15 at 9:59




Your kill -SIGSTOP < /tmp/TimChromepid.PSD suggests that kill reads a PID from stdin — which it doesn't, thus the usage message. Try kill -SIGSTOP $(cat /tmp/TimChromepid.PSD) instead.
– PerlDuck
May 15 at 9:59












@Mark Have you tried adding bash in front of the script name to provide a shell when registering the keyboard shortcut?
– dsstorefile1
May 15 at 11:31





@Mark Have you tried adding bash in front of the script name to provide a shell when registering the keyboard shortcut?
– dsstorefile1
May 15 at 11:31





1




1




@dsstorefile1 Yes, that did it, thank you! :)
– Mark
May 16 at 7:35




@dsstorefile1 Yes, that did it, thank you! :)
– Mark
May 16 at 7:35












Did you fix the shebang? Please edit your question and change the code accordingly. To read the PID from the file you can do kill -SIGSPEC $(</tmp/TimChromepid.PSD) or use cat as shown by @PerlDuck. Please add some echo lines to test and redirect the whole output to a log file, especially that of kill with &>/path/to/logfile, then provide the content of the log file.
– dessert
May 16 at 7:59




Did you fix the shebang? Please edit your question and change the code accordingly. To read the PID from the file you can do kill -SIGSPEC $(</tmp/TimChromepid.PSD) or use cat as shown by @PerlDuck. Please add some echo lines to test and redirect the whole output to a log file, especially that of kill with &>/path/to/logfile, then provide the content of the log file.
– dessert
May 16 at 7:59










1 Answer
1






active

oldest

votes

















up vote
1
down vote













I don't think the problem has something to do with whether the script is run via keyboard shortcut or directly in a terminal. It's rather an error in your if branch and the script will alternately work and fail.



In the if branch you wrote



kill -SIGSTOP < /tmp/TimChromepid.PSD


which means: pipe the content of file /tmp/TimChromepid.PSD into kill's stdin. But kill doesn't read anything from stdin, it just accepts the PID as a command line parameter, which wasn't given. That's why it told you about its usage.



To fix it, simply do as you did in the else branch, i.e. either replace kill -SIGSTOP < /tmp/TimChromepid.PSD with kill -SIGSTOP $(< /tmp/TimChromepid.PSD) or use $NMR:



#!/bin/sh
if [ -f /tmp/TimChromepid.RUN ]; then
mv /tmp/TimChromepid.RUN /tmp/TimChromepid.PSD
NMR=$(< /tmp/TimChromepid.PSD)
kill -SIGSTOP $NMR
else
NMR=$(< /tmp/TimChromepid.PSD)
mv /tmp/TimChromepid.PSD /tmp/TimChromepid.RUN
kill -SIGCONT $NMR
fi





share|improve this answer




















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "89"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );








     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1036425%2fyoutube-pausing-script-works-from-command-line-but-not-from-shortcut%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    I don't think the problem has something to do with whether the script is run via keyboard shortcut or directly in a terminal. It's rather an error in your if branch and the script will alternately work and fail.



    In the if branch you wrote



    kill -SIGSTOP < /tmp/TimChromepid.PSD


    which means: pipe the content of file /tmp/TimChromepid.PSD into kill's stdin. But kill doesn't read anything from stdin, it just accepts the PID as a command line parameter, which wasn't given. That's why it told you about its usage.



    To fix it, simply do as you did in the else branch, i.e. either replace kill -SIGSTOP < /tmp/TimChromepid.PSD with kill -SIGSTOP $(< /tmp/TimChromepid.PSD) or use $NMR:



    #!/bin/sh
    if [ -f /tmp/TimChromepid.RUN ]; then
    mv /tmp/TimChromepid.RUN /tmp/TimChromepid.PSD
    NMR=$(< /tmp/TimChromepid.PSD)
    kill -SIGSTOP $NMR
    else
    NMR=$(< /tmp/TimChromepid.PSD)
    mv /tmp/TimChromepid.PSD /tmp/TimChromepid.RUN
    kill -SIGCONT $NMR
    fi





    share|improve this answer
























      up vote
      1
      down vote













      I don't think the problem has something to do with whether the script is run via keyboard shortcut or directly in a terminal. It's rather an error in your if branch and the script will alternately work and fail.



      In the if branch you wrote



      kill -SIGSTOP < /tmp/TimChromepid.PSD


      which means: pipe the content of file /tmp/TimChromepid.PSD into kill's stdin. But kill doesn't read anything from stdin, it just accepts the PID as a command line parameter, which wasn't given. That's why it told you about its usage.



      To fix it, simply do as you did in the else branch, i.e. either replace kill -SIGSTOP < /tmp/TimChromepid.PSD with kill -SIGSTOP $(< /tmp/TimChromepid.PSD) or use $NMR:



      #!/bin/sh
      if [ -f /tmp/TimChromepid.RUN ]; then
      mv /tmp/TimChromepid.RUN /tmp/TimChromepid.PSD
      NMR=$(< /tmp/TimChromepid.PSD)
      kill -SIGSTOP $NMR
      else
      NMR=$(< /tmp/TimChromepid.PSD)
      mv /tmp/TimChromepid.PSD /tmp/TimChromepid.RUN
      kill -SIGCONT $NMR
      fi





      share|improve this answer






















        up vote
        1
        down vote










        up vote
        1
        down vote









        I don't think the problem has something to do with whether the script is run via keyboard shortcut or directly in a terminal. It's rather an error in your if branch and the script will alternately work and fail.



        In the if branch you wrote



        kill -SIGSTOP < /tmp/TimChromepid.PSD


        which means: pipe the content of file /tmp/TimChromepid.PSD into kill's stdin. But kill doesn't read anything from stdin, it just accepts the PID as a command line parameter, which wasn't given. That's why it told you about its usage.



        To fix it, simply do as you did in the else branch, i.e. either replace kill -SIGSTOP < /tmp/TimChromepid.PSD with kill -SIGSTOP $(< /tmp/TimChromepid.PSD) or use $NMR:



        #!/bin/sh
        if [ -f /tmp/TimChromepid.RUN ]; then
        mv /tmp/TimChromepid.RUN /tmp/TimChromepid.PSD
        NMR=$(< /tmp/TimChromepid.PSD)
        kill -SIGSTOP $NMR
        else
        NMR=$(< /tmp/TimChromepid.PSD)
        mv /tmp/TimChromepid.PSD /tmp/TimChromepid.RUN
        kill -SIGCONT $NMR
        fi





        share|improve this answer












        I don't think the problem has something to do with whether the script is run via keyboard shortcut or directly in a terminal. It's rather an error in your if branch and the script will alternately work and fail.



        In the if branch you wrote



        kill -SIGSTOP < /tmp/TimChromepid.PSD


        which means: pipe the content of file /tmp/TimChromepid.PSD into kill's stdin. But kill doesn't read anything from stdin, it just accepts the PID as a command line parameter, which wasn't given. That's why it told you about its usage.



        To fix it, simply do as you did in the else branch, i.e. either replace kill -SIGSTOP < /tmp/TimChromepid.PSD with kill -SIGSTOP $(< /tmp/TimChromepid.PSD) or use $NMR:



        #!/bin/sh
        if [ -f /tmp/TimChromepid.RUN ]; then
        mv /tmp/TimChromepid.RUN /tmp/TimChromepid.PSD
        NMR=$(< /tmp/TimChromepid.PSD)
        kill -SIGSTOP $NMR
        else
        NMR=$(< /tmp/TimChromepid.PSD)
        mv /tmp/TimChromepid.PSD /tmp/TimChromepid.RUN
        kill -SIGCONT $NMR
        fi






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered May 21 at 12:15









        PerlDuck

        3,64911030




        3,64911030






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1036425%2fyoutube-pausing-script-works-from-command-line-but-not-from-shortcut%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            Which professions warranted travel in Medieval times?

            How do so many people here on Academia.SE, and in general, afford lavish higher education programs?

            Trouble downloading packages list due to a “Hash sum mismatch” error