Search code examples
bashshellxdotool

Error: Can't open display: (null) Failed creating new xdo instance on mac OS


I looked at many answers on internet but no solutions helped. When I just do open http://google.com it works, my default browser is Google Chrome. I downloaded xdotool package via brew What I want to do is, to open the webpage(any webpage) and refresh it in every 10 seconds, I have the following code:

#!/bin/bash
while true;
do
    export DISPLAY=:0.0
    export XAUTHORITY=/home/dogaister/.Xauthority
    open  http://google.com
    xdotool key command+r
    sleep 10
done

I also tried DISPLAY=':0' or DISPLAY=':0.0', they didn't work either.


Solution

  • #!/bin/bash
    while true;
    do
        osascript -e 'tell application "Google Chrome" to reload (tabs of window 1 whose URL contains "google.ca")'
        sleep 10
        echo "Reloaded"
    done
    

    worked. Thanks to Mark Setchell for his contribution