Removing the text, Applescript

101 Views Asked by At

So I've made a script that will allow me to copy the sender of the email and paste it into the Numbers document, the copied addresses list two different emails and I need to remove one of them.

      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 recipients 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

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

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

1

There are 1 best solutions below

0
On

You can split all the senders into individual text items and choose to only copy the first mail address, like shown below. You can change text item 1 to another text item if you want to keep the second address and remove the first.

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 recipients of aMessage, " OR"}
    end repeat

    set AppleScript's text item delimiters to " "
    -- Set all the senders to a string
    set allSenders to (theSenderList as string)
    -- Sort these senders by " Or "
    set AppleScript's text item delimiters to " OR "

    -- Get every sender as an individual text item
    set everySender to every text item of allSenders

    -- Set the clipboard to the first sender
    set the clipboard to (item 1 of everySender as string)

    beep
end tell

tell application "Numbers"
    -- Try to add to open document in Numbers
    try
        tell document 1 to tell sheet 1 to tell table 1
            set value of cell "a1" to (the clipboard as text)
            set value of cell "b1" to current date
        end tell
    on error -- Create a new document if there is currently no document open
        set myDocument to make new document
        tell document 1 to tell sheet 1 to tell table 1
            set value of cell "a1" to (the clipboard as text)
            set value of cell "b1" to current date
        end tell
    end try
end tell