New topic: 

RealStudio, Applescript and accents

<http://forums.realsoftware.com/viewtopic.php?t=46543>

         Page 1 of 1
   [ 4 posts ]                 Previous topic | Next topic          Author  
Message        lo5co          Post subject: RealStudio, Applescript and 
accentsPosted: Sun Jan 13, 2013 10:26 am                         
Joined: Sun Jan 13, 2013 10:17 am
Posts: 2                Hi all,
I have to create a message in Apple Mail from RealStudio through Applescript 
passing mail address, subject, body and attachment.
All works well except when one of those field contains characters with accents 
(like è, ò, à, ù, ì, etc).
Could someone help me?

Thank you!
Giacomo

Here's the code I use:

dim doc as new PDFDocumentMBS
dim page as new StampaPreventivo

// set page size
dim r as new NSRectMBS(0, 0, 595, 842) // DIN A4 paper
page.boundsForBox(page.kPDFDisplayBoxMediaBox) = r


// add page
doc.insertPage(page, 0)

// write page

dim cartella as FolderItem = SpecialFolder.Desktop.Child("PreventiviASP")
if cartella.exists = false then
  cartella.CreateAsFolder
end

dim file as FolderItem = cartella.Child(DettaglioRiparazione.CampoRmaId.Text + 
" - " +DettaglioRiparazione.campodenominazione.Text + "-" + 
DettaglioRiparazione.CampoSerial.Text+".pdf")
if file.Exists then
  file.Delete
end if


if doc.write(file) then
  
  // CREO UNA MAIL CON ALLEGATO TRAMITE APPLESCRIPT
  
  dim nomedestinatario as String = campodenominazione.Text
  dim maildestinatario as String = CampoMail.text
  dim soggetto as String = "Invio Preventivo"
  dim corpodelmessaggio(-1) as String
  corpodelmessaggio.Append "Gentile Cliente,"
  corpodelmessaggio.Append EndOfLine
  corpodelmessaggio.Append EndOfLine
  corpodelmessaggio.Append "alleghiamo alla presente il documento in oggetto."
  corpodelmessaggio.Append EndOfLine
  corpodelmessaggio.Append "Con l'occasione, porgiamo distinti saluti."
  corpodelmessaggio.Append EndOfLine
  corpodelmessaggio.Append EndOfLine
  corpodelmessaggio.Append "C & C Consulting S.r.l."
  corpodelmessaggio.Append EndOfLine
  corpodelmessaggio.Append "Area Amministrativa"
  corpodelmessaggio.Append EndOfLine
  
  dim corpodelmessaggiounito as String = Join(corpodelmessaggio)
  dim percorsofile as String = 
ConvertEncoding(file.AbsolutePath,Encodings.SystemDefault)
  MsgBox percorsofile
  
  //MsgBox percorsofile
  
  dim a as AppleScriptMBS
  
  a=new AppleScriptMBS
  dim lines(-1) as string
  
  
  
  //lines.Append "set theName to """ + nomedestinatario + """"
  lines.Append "set theAddress to """ + maildestinatario + """"
  lines.Append "set theSubject to """ + soggetto + """"
  lines.Append "set theBody to """ + corpodelmessaggiounito + """"
  lines.Append "set theAttachment to """ + percorsofile + """"
  lines.Append "set theFile to alias theAttachment"
  
  
  lines.Append "tell application ""Mail"""
  
  lines.Append "set newMessage to make new outgoing message with properties 
{subject:theSubject, content:theBody & return & return}"
  lines.Append "tell newMessage"
  
  lines.Append "set visible to true"
  //lines.Append "make new to recipient at end of to recipients with properties 
{name:theName, address:theAddress}"
  lines.Append "make new to recipient at end of to recipients with properties 
{address:theAddress}"
  lines.Append "tell content"
  lines.Append "make new attachment with properties {file name:theFile} at 
after the last paragraph"
  lines.Append "end tell"
  lines.Append "end tell"
  
  lines.Append "activate"
  lines.Append "end tell"
  lines.Append "end"
  
  a.Compile Join(lines, EndOfLine.Macintosh)
  if a.Lasterror<>0 then
  MsgBox "Apple Script error: 
"+str(a.Lasterror)+EndOfLine+EndOfLine+a.Error.BriefMessage
  end if
  a.Execute
  if a.Lasterror<>0 then
  MsgBox "Apple Script error: 
"+str(a.Lasterror)+EndOfLine+EndOfLine+a.Error.BriefMessage
  end if
  
else
  MsgBox "Failed to write file."
end if
   
                             Top                npalardy          Post subject: 
Re: RealStudio, Applescript and accentsPosted: Sun Jan 13, 2013 11:48 am        
               Real Software Engineer          
Joined: Sat Dec 24, 2005 8:18 pm
Posts: 7674
Location: Canada, Alberta, Near Red Deer                Well since you are 
doing this in MBS have you asked Christian ?

Writing this directly in applescript editor works

set theSubject to "éáë"
  set theBody to "éáë"
  
  tell application "Mail"
  
  set newMessage to make new outgoing message with properties 
{subject:theSubject, content:theBody & return & return}
  tell newMessage
  
  set visible to true
  end tell
  end tell
  end
      
_________________
My web site Great White Software
RBLibrary.com REALbasic learning  
                             Top                ktekinay          Post subject: 
Re: RealStudio, Applescript and accentsPosted: Sun Jan 13, 2013 11:58 am        
                         
Joined: Mon Feb 05, 2007 5:21 pm
Posts: 354
Location: New York, NY                Modify your code in two places:
a=new AppleScriptMBS
a.UnicodeText = true
..
a.Compile Join(lines, EndOfLine.Macintosh).ConvertEncoding( Encodings.UTF16 )

You should also consider adding this:
dim corpodelmessaggiounito as String = Join(corpodelmessaggio)
corpodelmessaggiounito = corpodelmessaggiounito.ReplaceAll( """", "\""" )

This will replace all quotes with \". Otherwise, your script will fail if you 
mistakenly add a quote to the body later.      
_________________
Kem Tekinay
MacTechnologies Consulting
http://www.mactechnologies.com/

Need to develop, test, and refine regular expressions? Try RegExRX.
  
                             Top                lo5co          Post subject: 
Re: RealStudio, Applescript and accentsPosted: Sun Jan 13, 2013 5:19 pm         
                
Joined: Sun Jan 13, 2013 10:17 am
Posts: 2                ktekinay wrote:Modify your code in two places:
a=new AppleScriptMBS
a.UnicodeText = true
..
a.Compile Join(lines, EndOfLine.Macintosh).ConvertEncoding( Encodings.UTF16 )

You should also consider adding this:
dim corpodelmessaggiounito as String = Join(corpodelmessaggio)
corpodelmessaggiounito = corpodelmessaggiounito.ReplaceAll( """", "\""" )

This will replace all quotes with \". Otherwise, your script will fail if you 
mistakenly add a quote to the body later.

Thank you very much ktekinay, this works like a charm!   
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 4 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to