Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Wed Nov 20, 2019 2:13 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: RealStudio, Applescript and accents
PostPosted: Sun Jan 13, 2013 10:26 am 
Offline

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
 Profile  
Reply with quote  
 Post subject: Re: RealStudio, Applescript and accents
PostPosted: Sun Jan 13, 2013 11:48 am 
Offline
Real Software Engineer

Joined: Sat Dec 24, 2005 8:18 pm
Posts: 7858
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

_________________
Norman Palardy (Real Software)


Top
 Profile  
Reply with quote  
 Post subject: Re: RealStudio, Applescript and accents
PostPosted: Sun Jan 13, 2013 11:58 am 
Offline
User avatar

Joined: Mon Feb 05, 2007 5:21 pm
Posts: 600
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
 Profile  
Reply with quote  
 Post subject: Re: RealStudio, Applescript and accents
PostPosted: Sun Jan 13, 2013 5:19 pm 
Offline

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
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group