1

Here is the overall goal. Lets say I have 10 tabs open in a Safari window. I want to tab to the correct open field in the first Safari tab.

  • Type a string of text.
  • Hit the "send" button below this field.
  • Move to the next Safari tab
  • repeat this process until the same text has been submitted in all open tabs.

The code below does everything but clicking the send button. When I "inspect element" on the "send" button here is what I see:

<input type=“submit” class=“submit” value=“Send”> = $0

Can someone tell me how to modify my code to use that and get the send button clicked on each page? Here is the code I have so far (I am brand new to AppleScript, btw)

tell application "Safari"
    activate
end tell

tell application "Safari"
    set tabList to every tab of window 1
    repeat with currentTab in tabList
        
        tell application "System Events"
            delay 1
            keystroke tab
            keystroke tab
            keystroke tab
            keystroke tab
            delay 2
            keystroke "text i want on each page"
            delay 1
            delay 1
            tell application "System Events" to key code 30 using {shift down, command down}
        end tell
    end repeat
end tell

1

1 Answer 1

1

I seem to have figured it out (with some chatGPT assistance that actually worked). The key line of code to add was:

Here is the full code that works so you can see it in context


tell application "Safari"
    activate
end tell

tell application "Safari"
    set tabList to every tab of window 1
    repeat with currentTab in tabList
        
        tell application "System Events"
            delay 1
            keystroke tab
            keystroke tab
            keystroke tab
            keystroke tab
            delay 2
            keystroke "text I want on each page"
            delay 1
        end tell

        tell application "Safari"
            delay 1
            do JavaScript "document.querySelector('.submit').click();" in current tab of window 1
        end tell

        tell application "System Events" to key code 30 using {shift down, command down}
    end repeat
end tell

2
  • Note that you are missing the formatting for the first two and last lines of your script.
    – Peter M
    Jan 9 at 20:09
  • 2
    I edited your answer; fixed the code formatting and removed the follow up question. Please remember this is not a threaded forum, but a Q&A site where there’s one question/topic per post. If you have another question, feel free to post a new one (but check that it hasn’t already been asked!)
    – Allan
    Jan 9 at 22:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .