Saturday, September 19, 2020

#1 2020-09-16 07:11:07 am

drpeppershaker
Member
Registered: 2016-12-18
Posts: 17

Mail -- make some text bold if it starts with a three digit number?

Hi, I have a snippet of applescript that I use to make automatically generated emails.

Previously, the script was looking for any paragraph that started with "Ep" and making the first two words of that paragraph bold. 

But now, the email body has changed, and I need to make the first two words of any paragraph that starts with a three digit number bold. I've searched around, but I don't know exactly how to get applescript to look for a paragraph starting ANY three digit number  001-999.

EDIT:
Include numbers such as 001, but not 1. Must have 3 digits and 3 digits only.


Snippet of my previous version of the script:

Applescript:


tell application "Mail"
   activate
   
   set emailSubject to (productionDayDate & " Daily Reports") as rich text
   
   set theMessage to make new outgoing message with properties {visible:true, subject:emailSubject, content:emailContent}
   
   tell theMessage
       set font of (words 1 thru 2 of (every paragraph where the first word starts with "Ep")) to "Helvetica Bold"
       
       make new to recipient at end of to recipients with properties {address:emailList}
   end tell

Any help would be greatly appreciated. Thank you

Last edited by drpeppershaker (2020-09-16 07:16:58 am)

Offline

 

#2 2020-09-16 06:04:50 pm

Marc Anthony
Member
From:: Dallas, TX
Registered: 2006-04-27
Posts: 962

Re: Mail -- make some text bold if it starts with a three digit number?

Hi. A simple method would be to coerce the text.


Applescript:

tell application "Mail"
   activate
   set emailSubject to (" Daily Reports") as rich text
   set theMessage to make new outgoing message with properties {visible:true, subject:emailSubject, content:"1233 456 something
something else"
}
   tell theMessage to repeat with counter from 1 to (count theMessage's paragraphs)
       set paragraphs's properties to {color:{0, 0, 0}} --addresses an issue if dark mode is on
       if my detectNumtriad(theMessage's paragraph counter's word 1) then set paragraph counter's words 1 thru 2's font to "Helvetica Bold"
   end repeat
end tell


on detectNumtriad(this)
   set pass to true
   try
       this as number
   on error
       set pass to false
   end try
   if this's length is not 3 then set pass to false
   pass
end detectNumtriad

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)