bash에서 명령을 실행하고 키 입력을 보낼 수 있습니까?

bash에서 명령을 실행하고 키 입력을 보낼 수 있습니까?

bash에서 Firefox를 시작하려고 하는데 시작 시 웹 콘솔이 열리도록 하고 싶습니다. (시작 후 즉시 F12를 누르면 됩니다.) 프로그램을 시작하고 시작 시 F12 키를 보내는 bash 명령이 있습니까? xdotool을 살펴보고 Firefox를 시작한 다음 xdotool을 사용하여 키를 보내는 bash 스크립트를 만들려고 시도했지만 Firefox를 닫을 때까지 xdotool 명령이 실행되지 않습니다.

답변1

#!/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"

그러나 이것은 그다지 견고하지 않습니다. firefox콘솔을 열도록 직접 구성하는 것이 좋습니다.

관련 정보