Is it possible to start a command from bash and send a keystroke to it











up vote
2
down vote

favorite












I'm trying to start Firefox from bash and I want it to open the webconsole on start (this can be done by pressing F12 rigth after it started). Is there a bash command that starts the programm and sends the F12 key while starting? I already looked at xdotool and tried to create a bash script, that starts firefox and then sends the key with xdotool, but the xdotool command isn't run until I close firefox.










share|improve this question




















  • 1




    Hmm, you could background firefox with firefox & and then kluge in a sleep 7 or something to wait for firefox to spin up. A better solution might be to configure firefox to show the webconsole by default, but that might require an add-on or delving through about:config ?
    – thrig
    Sep 13 '15 at 19:59










  • I already searched for methods that start the webconsole, but the only option I found is the -jsconsole option and that starts the browserconsole instead of the webconsole. I haven't found any config options or addons that do this, thats why I'm searching for a way to do it in a bash script.
    – user134007
    Sep 13 '15 at 20:04

















up vote
2
down vote

favorite












I'm trying to start Firefox from bash and I want it to open the webconsole on start (this can be done by pressing F12 rigth after it started). Is there a bash command that starts the programm and sends the F12 key while starting? I already looked at xdotool and tried to create a bash script, that starts firefox and then sends the key with xdotool, but the xdotool command isn't run until I close firefox.










share|improve this question




















  • 1




    Hmm, you could background firefox with firefox & and then kluge in a sleep 7 or something to wait for firefox to spin up. A better solution might be to configure firefox to show the webconsole by default, but that might require an add-on or delving through about:config ?
    – thrig
    Sep 13 '15 at 19:59










  • I already searched for methods that start the webconsole, but the only option I found is the -jsconsole option and that starts the browserconsole instead of the webconsole. I haven't found any config options or addons that do this, thats why I'm searching for a way to do it in a bash script.
    – user134007
    Sep 13 '15 at 20:04















up vote
2
down vote

favorite









up vote
2
down vote

favorite











I'm trying to start Firefox from bash and I want it to open the webconsole on start (this can be done by pressing F12 rigth after it started). Is there a bash command that starts the programm and sends the F12 key while starting? I already looked at xdotool and tried to create a bash script, that starts firefox and then sends the key with xdotool, but the xdotool command isn't run until I close firefox.










share|improve this question















I'm trying to start Firefox from bash and I want it to open the webconsole on start (this can be done by pressing F12 rigth after it started). Is there a bash command that starts the programm and sends the F12 key while starting? I already looked at xdotool and tried to create a bash script, that starts firefox and then sends the key with xdotool, but the xdotool command isn't run until I close firefox.







bash shell-script scripting






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday









Rui F Ribeiro

38.6k1479128




38.6k1479128










asked Sep 13 '15 at 19:39







user134007















  • 1




    Hmm, you could background firefox with firefox & and then kluge in a sleep 7 or something to wait for firefox to spin up. A better solution might be to configure firefox to show the webconsole by default, but that might require an add-on or delving through about:config ?
    – thrig
    Sep 13 '15 at 19:59










  • I already searched for methods that start the webconsole, but the only option I found is the -jsconsole option and that starts the browserconsole instead of the webconsole. I haven't found any config options or addons that do this, thats why I'm searching for a way to do it in a bash script.
    – user134007
    Sep 13 '15 at 20:04
















  • 1




    Hmm, you could background firefox with firefox & and then kluge in a sleep 7 or something to wait for firefox to spin up. A better solution might be to configure firefox to show the webconsole by default, but that might require an add-on or delving through about:config ?
    – thrig
    Sep 13 '15 at 19:59










  • I already searched for methods that start the webconsole, but the only option I found is the -jsconsole option and that starts the browserconsole instead of the webconsole. I haven't found any config options or addons that do this, thats why I'm searching for a way to do it in a bash script.
    – user134007
    Sep 13 '15 at 20:04










1




1




Hmm, you could background firefox with firefox & and then kluge in a sleep 7 or something to wait for firefox to spin up. A better solution might be to configure firefox to show the webconsole by default, but that might require an add-on or delving through about:config ?
– thrig
Sep 13 '15 at 19:59




Hmm, you could background firefox with firefox & and then kluge in a sleep 7 or something to wait for firefox to spin up. A better solution might be to configure firefox to show the webconsole by default, but that might require an add-on or delving through about:config ?
– thrig
Sep 13 '15 at 19:59












I already searched for methods that start the webconsole, but the only option I found is the -jsconsole option and that starts the browserconsole instead of the webconsole. I haven't found any config options or addons that do this, thats why I'm searching for a way to do it in a bash script.
– user134007
Sep 13 '15 at 20:04






I already searched for methods that start the webconsole, but the only option I found is the -jsconsole option and that starts the browserconsole instead of the webconsole. I haven't found any config options or addons that do this, thats why I'm searching for a way to do it in a bash script.
– user134007
Sep 13 '15 at 20:04












1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










#!/bin/sh 
set -e #abort if anything fails
firefox & #run firefox in the background
pid=$! #remember its pid

#Poll X until firefox sets up a window
#remember the X id of the window
while [ -z "$id" ]; do
id=$(xdotool search --onlyvisible --pid $pid)
sleep 0.1 #poll interval
done

#Bring the window to the front and send it the F12 key
xdotool windowactivate $id && xdotool key F12
disown "$pid"


This isn't very robust, though. Configuring firefox to open the console by itself would be better.






share|improve this answer



















  • 1




    Is there an urgent call from the NYSE for some risky business? If not then sleep 1 is fully sufficient.
    – ott--
    Sep 13 '15 at 20:37











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f229459%2fis-it-possible-to-start-a-command-from-bash-and-send-a-keystroke-to-it%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown
























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










#!/bin/sh 
set -e #abort if anything fails
firefox & #run firefox in the background
pid=$! #remember its pid

#Poll X until firefox sets up a window
#remember the X id of the window
while [ -z "$id" ]; do
id=$(xdotool search --onlyvisible --pid $pid)
sleep 0.1 #poll interval
done

#Bring the window to the front and send it the F12 key
xdotool windowactivate $id && xdotool key F12
disown "$pid"


This isn't very robust, though. Configuring firefox to open the console by itself would be better.






share|improve this answer



















  • 1




    Is there an urgent call from the NYSE for some risky business? If not then sleep 1 is fully sufficient.
    – ott--
    Sep 13 '15 at 20:37















up vote
2
down vote



accepted










#!/bin/sh 
set -e #abort if anything fails
firefox & #run firefox in the background
pid=$! #remember its pid

#Poll X until firefox sets up a window
#remember the X id of the window
while [ -z "$id" ]; do
id=$(xdotool search --onlyvisible --pid $pid)
sleep 0.1 #poll interval
done

#Bring the window to the front and send it the F12 key
xdotool windowactivate $id && xdotool key F12
disown "$pid"


This isn't very robust, though. Configuring firefox to open the console by itself would be better.






share|improve this answer



















  • 1




    Is there an urgent call from the NYSE for some risky business? If not then sleep 1 is fully sufficient.
    – ott--
    Sep 13 '15 at 20:37













up vote
2
down vote



accepted







up vote
2
down vote



accepted






#!/bin/sh 
set -e #abort if anything fails
firefox & #run firefox in the background
pid=$! #remember its pid

#Poll X until firefox sets up a window
#remember the X id of the window
while [ -z "$id" ]; do
id=$(xdotool search --onlyvisible --pid $pid)
sleep 0.1 #poll interval
done

#Bring the window to the front and send it the F12 key
xdotool windowactivate $id && xdotool key F12
disown "$pid"


This isn't very robust, though. Configuring firefox to open the console by itself would be better.






share|improve this answer














#!/bin/sh 
set -e #abort if anything fails
firefox & #run firefox in the background
pid=$! #remember its pid

#Poll X until firefox sets up a window
#remember the X id of the window
while [ -z "$id" ]; do
id=$(xdotool search --onlyvisible --pid $pid)
sleep 0.1 #poll interval
done

#Bring the window to the front and send it the F12 key
xdotool windowactivate $id && xdotool key F12
disown "$pid"


This isn't very robust, though. Configuring firefox to open the console by itself would be better.







share|improve this answer














share|improve this answer



share|improve this answer








edited Sep 13 '15 at 20:55

























answered Sep 13 '15 at 20:06









PSkocik

17.6k44994




17.6k44994








  • 1




    Is there an urgent call from the NYSE for some risky business? If not then sleep 1 is fully sufficient.
    – ott--
    Sep 13 '15 at 20:37














  • 1




    Is there an urgent call from the NYSE for some risky business? If not then sleep 1 is fully sufficient.
    – ott--
    Sep 13 '15 at 20:37








1




1




Is there an urgent call from the NYSE for some risky business? If not then sleep 1 is fully sufficient.
– ott--
Sep 13 '15 at 20:37




Is there an urgent call from the NYSE for some risky business? If not then sleep 1 is fully sufficient.
– ott--
Sep 13 '15 at 20:37


















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f229459%2fis-it-possible-to-start-a-command-from-bash-and-send-a-keystroke-to-it%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

サソリ

広島県道265号伴広島線

Setup Asymptote in Texstudio