0
votes

I am trying to get this script to click "replace all" using keystrokes.

I am getting an error:

"System Events got an error: Can’t get button \"Replace All\"." number -1728 from button "Replace All"

tell application "Mail"
    set theSenderList to {}
    set theMessages to the selected messages of message viewer 0
    repeat with aMessage in theMessages
        set end of theSenderList to {address of to recipient of aMessage, " OR"}
    end repeat
    set AppleScript's text item delimiters to " "
    set the clipboard to (theSenderList as string)
    set AppleScript's text item delimiters to " "
    beep
end tell

set clip to (the clipboard as text)
tell application "Numbers" to tell document 1 to tell sheet 1 to tell table 1
    set value of cell "a9" to clip
end tell

tell application "Numbers" to tell document 1 to tell sheet 1 to tell table 1
    set value of cell "b9" to current date
end tell

tell application "Numbers"
    activate
end tell
tell application "System Events"
    delay 1.0
    keystroke "f" using command down
    keystroke "@gmail.com"
    keystroke tab
    keystroke ""
    delay 2
    click button "Replace All"
end tell
1

1 Answers

0
votes

It appears that you are trying to replace the occurrence of "@gmail.com" in a bunch of email addresses with blanks, thus deleting that portion of the address. You could do that much more easily in plain AppleScript:

set targetAddresses to {"[email protected]", "[email protected]", "[email protected]"}

set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "@gmail.com"
set fixedAddresses to {}
repeat with eachAddress in targetAddresses
    set end of fixedAddresses to text item 1 of eachAddress
end repeat
set AppleScript's text item delimiters to astid
fixedAddresses

-->{"fred", "wilma", "barney"}

Is this close to what you are trying to achieve?