0

I'm trying to incorporate following tasks.

  1. Refresh Safari every minute

  2. After every refresh, press the down and right arrow at specific intervals.

My Attempt

I rattempted the following code but it's not working. The refreshSafari gets called once but doesn't get called again. simulateRightArrowKeyPress works fine as expected.

-- Function to simulate the right arrow key press
on simulateRightArrowKeyPress()
    repeat
        tell application "Safari"
            activate
        end tell
        
        delay 2
        
        tell application "System Events"
            key code 125
        end tell
        
        delay 3
        
        tell application "System Events"
            key code 124
        end tell
    end repeat
end simulateRightArrowKeyPress

-- Function to refresh Safari
on refreshSafari()
    tell application "Safari"
        tell front window
            do JavaScript "location.reload();" in current tab
        end tell
    end tell
end refreshSafari

-- Function to run the combined task
on runScheduledTask()
    repeat
        refreshSafari()
        simulateRightArrowKeyPress()
        delay (1 * 60) -- x minutes in seconds      
    end repeat
end runScheduledTask

-- Call the function to run the combined task
runScheduledTask()
2
  • You should be able to refresh just using tell application "System Events" to keystroke "R" using command down
    – Tetsujin
    Commented Oct 30, 2023 at 8:37
  • it happens the first time but not the second time. I then realized the key related function blocked the thread with repeat loop, so I ended up creating two scripts in separate windows and ran both of them.
    – Source
    Commented Oct 30, 2023 at 13:42

0

You must log in to answer this question.

Browse other questions tagged .