2

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.

  • 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
2
#!/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.

  • 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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy