2015-05-19 75 views
0

所以我做了一個腳本,允許我複製電子郵件的發件人並將其粘貼到Numbers文檔中,複製的地址列出兩個不同的電子郵件,我需要刪除其中的一個。刪除文本,Applescript

 tell application "Mail" 
 
\t set theSenderList to {} 
 
\t set theMessages to the selected messages of message viewer 0 
 
\t repeat with aMessage in theMessages 
 
\t \t set end of theSenderList to {address of to recipients of aMessage, " OR"} 
 
\t end repeat 
 
\t set AppleScript's text item delimiters to " " 
 
\t set the clipboard to (theSenderList as string) 
 
\t 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 
 
\t 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 
 
\t set value of cell "b1" to current date 
 
end tell

回答

0

您可以分割所有發件人爲單獨的文本項並選擇只複製第一個郵件地址,如下圖所示。如果您想保留第二個地址並刪除第一個地址,您可以將text item 1更改爲另一個文本項目。

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