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 &quot;System Events&quot;
        delay 1
        keystroke tab
        keystroke tab
        keystroke tab
        keystroke tab
        delay 2
        keystroke &quot;text i want on each page&quot;
        delay 1
        delay 1
        tell application &quot;System Events&quot; to key code 30 using {shift down, command down}
    end tell
end repeat

end tell

Allan
  • 101,432
  • 1
    Is the button always in the same place? See https://apple.stackexchange.com/questions/266784/how-do-i-make-the-mouse-click-at-current-location-using-applescript – Tetsujin Jan 09 '23 at 16:55

1 Answers1

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 &quot;System Events&quot;
        delay 1
        keystroke tab
        keystroke tab
        keystroke tab
        keystroke tab
        delay 2
        keystroke &quot;text I want on each page&quot;
        delay 1
    end tell

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

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

end tell

Allan
  • 101,432
  • Note that you are missing the formatting for the first two and last lines of your script. – Peter M Jan 09 '23 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 09 '23 at 22:52