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

前端 未结 7 992
清歌不尽
清歌不尽 2020-12-31 23:52

Given:

I have Firefox with the [Firefox Page Title] page open on my Ubuntu computer.

Here is my command:

7条回答
  •  死守一世寂寞
    2021-01-01 00:17

    After trying several different approaches to get xdotool to work correctly, I'm inclined to believe that xdotool itself is the issue. Here is what I tried, none worked.

    • Running the command (and variations - removing/adding args) from Terminal.
    • Running the command (and variations - removing/adding args) from a SH script.
    • Changing between F5 and ctrl+r keys, as they should both refresh a Firefox page.
    • Trying other parameters, such as:
      • --window to set the window the keys are to be sent to.
      • --delay to add a delay before the key is sent, after the window is focused.
      • Adding a sleep before the key is sent, after the window is focused.

    I also tried these commands in a script, as the frontpage for xdotool recommends, although it states this is the "older" version, as it is separated into multiple commands. The "new" version was the version I was trying to execute before and is a single command (see question).

    WID=`xdotool search "Firefox Page Title"`
    xdotool windowactivate --sync $WID
    xdotool key --clearmodifiers ctrl+r
    

    All of the above attempts ALWAYS correctly focused to the window I wanted, but it does not send the key whether it was F5 or ctrl+r.

    However, the following worked correctly:

    xdotool selectwindow key ctrl+r
    

    OR

    xdotool selectwindow key F5
    

    The selectwindow command, when executed, turns your cursor into a rectangular selection tool at which point you can select the window you want to be focused and, in this case, what window to send either the ctrl+r or F5 key to. Unfortunately, this is not what I was looking for, as it requires user input to work correctly.

    Final Solution:

    My solution (since I was attempting to use xdotool to constantly refresh a web-page) was to use the ReloadEvery Firefox add-on, which refreshes any page you set it on in any time interval you choose. It is intended to be a replica of the Opera browser's built-in automatic page refresh feature, and thus far, it works well.

    For those of you who use Chrome and are looking for a similar solution, there are plenty of add-ons available for you too. https://chrome.google.com/webstore/search/auto%20refresh

提交回复
热议问题