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

Clash 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?
command-line bash scripts shortcut-keys google-chrome
add a comment |Â
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?
command-line bash scripts shortcut-keys google-chrome
Yourkill -SIGSTOP < /tmp/TimChromepid.PSDsuggests thatkillreads a PID from stdin â which it doesn't, thus the usage message. Trykill -SIGSTOP $(cat /tmp/TimChromepid.PSD)instead.
â PerlDuck
May 15 at 9:59
@Mark Have you tried addingbashin 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 dokill -SIGSPEC $(</tmp/TimChromepid.PSD)or usecatas shown by @PerlDuck. Please add someecholines to test and redirect the whole output to a log file, especially that ofkillwith&>/path/to/logfile, then provide the content of the log file.
â dessert
May 16 at 7:59
add a comment |Â
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?
command-line bash scripts shortcut-keys google-chrome
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?
command-line bash scripts shortcut-keys google-chrome
edited May 21 at 9:22
Zanna
47.9k13118227
47.9k13118227
asked May 15 at 8:40
Mark
41
41
Yourkill -SIGSTOP < /tmp/TimChromepid.PSDsuggests thatkillreads a PID from stdin â which it doesn't, thus the usage message. Trykill -SIGSTOP $(cat /tmp/TimChromepid.PSD)instead.
â PerlDuck
May 15 at 9:59
@Mark Have you tried addingbashin 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 dokill -SIGSPEC $(</tmp/TimChromepid.PSD)or usecatas shown by @PerlDuck. Please add someecholines to test and redirect the whole output to a log file, especially that ofkillwith&>/path/to/logfile, then provide the content of the log file.
â dessert
May 16 at 7:59
add a comment |Â
Yourkill -SIGSTOP < /tmp/TimChromepid.PSDsuggests thatkillreads a PID from stdin â which it doesn't, thus the usage message. Trykill -SIGSTOP $(cat /tmp/TimChromepid.PSD)instead.
â PerlDuck
May 15 at 9:59
@Mark Have you tried addingbashin 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 dokill -SIGSPEC $(</tmp/TimChromepid.PSD)or usecatas shown by @PerlDuck. Please add someecholines to test and redirect the whole output to a log file, especially that ofkillwith&>/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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
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
answered May 21 at 12:15
PerlDuck
3,64911030
3,64911030
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Your
kill -SIGSTOP < /tmp/TimChromepid.PSDsuggests thatkillreads a PID from stdin â which it doesn't, thus the usage message. Trykill -SIGSTOP $(cat /tmp/TimChromepid.PSD)instead.â PerlDuck
May 15 at 9:59
@Mark Have you tried adding
bashin 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 usecatas shown by @PerlDuck. Please add someecholines to test and redirect the whole output to a log file, especially that ofkillwith&>/path/to/logfile, then provide the content of the log file.â dessert
May 16 at 7:59