Skip to main content
Inspiring
September 11, 2023
Answered

Create an elm file for new Outlook email

  • September 11, 2023
  • 1 reply
  • 506 views

I want to export an email template (.elm file) for Microsoft Outlook every time I compose a new email using Apple Script in InDesign script. I use the script as below, but it does not work 😞

var script = [
    'tell application "Microsoft Outlook"',
    "set theMessage to the first message in drafts",
    "tell me to saveMsg(theMessage)",
    "end tell",
    "to saveMsg(theMsg)",
    'set folderPath to ("Users:userName:Downloads:")',
    'if (do shell script "/bin/test -e " & quoted form of (POSIX path of folderPath) & " ; echo $?") is "1" then',
    'do shell script "/bin/mkdir -p " & quoted form of (POSIX path of folderPath)',
    "end if",
    'set timeStamp to do shell script "date +%Y%m%d%H%M%S"',
    'set emailSubject to "Test"',
    'set fileName to emailSubject & "_" & timeStamp',
    'set savePath to folderPath & fileName & ".eml" as string',
    "save theMsg in file (savePath)",
    "end saveMsg",
  ].join("\r");

app.doScript(
          script,
          ScriptLanguage.APPLESCRIPT_LANGUAGE,
          undefined,
          UndoModes.ENTIRE_SCRIPT,
          undefined
        )

Does any expert help me? I got stuck in it for around 3 hours :(((
Thank you in advance!

This topic has been closed for replies.
Correct answer ShaneLe147

Hi all,  I solved this issue by not using the function in the Applescript string saveMsg(theMsg) as below. Thank you all for spending your time on my case.

var script = [
    'tell application "Microsoft Outlook"',
    "set theMessage to the first message in drafts",
'set folderPath to ("Users:userName:Downloads:")',
    'if (do shell script "/bin/test -e " & quoted form of (POSIX path of folderPath) & " ; echo $?") is "1" then',
    'do shell script "/bin/mkdir -p " & quoted form of (POSIX path of folderPath)',
    "end if",
    'set timeStamp to do shell script "date +%Y%m%d%H%M%S"',
    'set emailSubject to "Test"',
    'set fileName to emailSubject & "_" & timeStamp',
    'set savePath to folderPath & fileName & ".eml" as string',
    "save theMsg in file (savePath)",
    "end tell"
  ].join("\r");

 

1 reply

BarlaeDC
Community Expert
Community Expert
September 15, 2023

Hi,

In what way does it not work?

 

Do you have a message in your drafts folder? if not you might want to change the first line to

set theMessage to make new outgoing message

 

ShaneLe147AuthorCorrect answer
Inspiring
September 19, 2023

Hi all,  I solved this issue by not using the function in the Applescript string saveMsg(theMsg) as below. Thank you all for spending your time on my case.

var script = [
    'tell application "Microsoft Outlook"',
    "set theMessage to the first message in drafts",
'set folderPath to ("Users:userName:Downloads:")',
    'if (do shell script "/bin/test -e " & quoted form of (POSIX path of folderPath) & " ; echo $?") is "1" then',
    'do shell script "/bin/mkdir -p " & quoted form of (POSIX path of folderPath)',
    "end if",
    'set timeStamp to do shell script "date +%Y%m%d%H%M%S"',
    'set emailSubject to "Test"',
    'set fileName to emailSubject & "_" & timeStamp',
    'set savePath to folderPath & fileName & ".eml" as string',
    "save theMsg in file (savePath)",
    "end tell"
  ].join("\r");