user13908778
user13908778

Reputation:

How to send a shortcut by bash to a program?

I like to send a shortcut for refreshing a tab to Firefox.

What I have:

What I have found / tryed:

What I tryed on terminal (dont get error message, a its looks for me, like i dont realy get a reload of webpage). It can be it send the output of terminal to the terminal and not to the firefox.:

xdotool key F5
xdotool key Ctrl + R

Question:

Remark and new knowledge:

Upvotes: 1

Views: 1387

Answers (2)

user13908778
user13908778

Reputation:

Now found the bug on bug tracker:

Found the follow bug reason:

"The fact that xdotool doesn't seem to work is probably related to applications detecting and discarding synthesized events:

Sending keystrokes to a specific window uses a different API than simply typing to the active window.

[...]

Many programs observe this flag and reject these events."

Source: Automatic web-page refresh using xdotool - not sending key after window focus

Found the follow solution:

"With that in mind I was able to make it work with the series of commands below. This reloads both Chromium and Firefox.

cwid=$(xdotool getwindowfocus) # Save the current window
twid=$(xdotool search --name somename)
xdotool windowactivate $twid
sleep 0.1 # The key event might be sent before the window has been fully activated
xdotool key --window $twid F5
xdotool windowactivate $cwid # Done, now go back to where we were

" Source: Automatic web-page refresh using xdotool - not sending key after window focus

Upvotes: 0

user13908778
user13908778

Reputation:

Sample for send F5 to browser by bash, for reload the page:

xdotool sleep 0.5 search --onlyvisible --classname Navigator windowactivate --sync key F5
xdotool sleep 0.5 search --onlyvisible --classname Navigator windowactivate --sync keyup F5

Sample for send Ctrl+F5 to browser by bash, for reload cache and the page:

xdotool sleep 0.5 search --onlyvisible --classname Navigator windowactivate --sync key Ctrl+F5
xdotool sleep 0.5 search --onlyvisible --classname Navigator windowactivate --sync keyup Ctrl
xdotool sleep 0.5 search --onlyvisible --classname Navigator windowactivate --sync keyup F5

Remark: The keyup fix the buggy xdotool a little bit.

Upvotes: 0

Related Questions