Reputation: 820
I asked the question Send email from clipboard without opening mail.app and got the code
set a to "[email protected]"
tell application "Mail"
tell (make new outgoing message)
set subject to (the clipboard)
set content to "content"
make new to recipient at end of to recipients with properties {address:a}
send
end tell
end tell
now I wonder, how could I have a script that do the same thing, but modifies it like this: if the Subject is the first 10 words, and iff the clipboard har more than 10 words, then the clipboard is cut off. For example like this "hello there baby this is a long message sent with... [see notes]" and then the enitre message (i.e. "hello there baby this is a long message sent with my new email, see you.") is in the content of the email.
Upvotes: 1
Views: 126
Reputation: 15996
Replace the set subject ...
and set content ...
lines in your script with the following:
if (count of words of (the clipboard)) is greater than 10 then set oldDelims to AppleScript's text item delimiters set AppleScript's text item delimiters to " " set subject to ((words 1 through 10 of (the clipboard)) & "... [see notes]") as text set AppleScript's text item delimiters to oldDelims set content to (the clipboard) else set subject to (the clipboard) set content to "content" end if
Links to references:
count of
gives the number of elements in a listwords of
splits a text string into a list, with each element representing a wordAppleScript's text item delimiters
can be manipulated to help split and join lists with different delimitersthrough
keyword can be used to get a subrange of items from a list@adayzdone has a good point - sometimes using words of
to split a string to a list then reassembly with text item delimiters
can mess up the input data. You could do this instead:
set oldDelims to AppleScript's text item delimiters set AppleScript's text item delimiters to " " set cblist to text items of (the clipboard) set AppleScript's text item delimiters to oldDelims if (count of cblist) is greater than 10 then set oldDelims to AppleScript's text item delimiters set AppleScript's text item delimiters to " " set subject to ((items 1 through 10 of cblist) & "... [see notes]") as text set AppleScript's text item delimiters to oldDelims set content to (the clipboard) else set subject to (the clipboard) set content to "content" end if
Upvotes: 2