3

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.

C.J
  • 169
  • 1
  • 12
  • Errr... you are barking up the wrong tree. Macs don't use `X11`, `DISPLAY` or `xdotool` - macOS does not even ship with an X11 server. You need to use Applescript. – Mark Setchell Sep 12 '18 at 19:31
  • @MarkSetchell I was getting an error before I downloaded `xdotool` but after I downloaded it didn't throw that error. Any solution or start point? I have never written and Applescript before – C.J Sep 12 '18 at 19:32
  • Try pasting this into Terminal to get an idea of how it goes... `osascript -e 'tell application "Google Chrome" to tell the active tab of its first window to reload'` – Mark Setchell Sep 12 '18 at 19:42
  • @MarkSetchell I just found the same answer, how can I specify the tab number? I wanna refresh the tab number 12 and every 10 seconds, this only refreshes once and using `repeat` causes not to download the page – C.J Sep 12 '18 at 19:43
  • Remove everything in your original script from `export DISPLAY` to `xdotool` and paste in the part I gave you in their place. – Mark Setchell Sep 12 '18 at 19:45
  • @MarkSetchell okay thanks, I will figure out the rest of it like specifying tabs etc. – C.J Sep 12 '18 at 19:48

1 Answers1

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

C.J
  • 169
  • 1
  • 12