Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

larour

macrumors newbie
Original poster
Sep 28, 2023
2
0
Hi,

I am trying to create a script to attach a file to an existing open Outlook email, from a Terminal. Call would go like this: ~/bin/attach temp.txt
Script attach reads:

#!/usr/bin/osascript
on run argv

set theFile to item 1 of argv as text

if not theFile starts with "/"
set theFile to (POSIX path of (POSIX file (do shell script "pwd") as alias)) & theFile
end if

set theAttachment to theFile as POSIX file
try
theAttachment as alias
on error
display dialog(theFile & " does not exist!")
end try

tell application "Microsoft Outlook"
set new_message to selection
if new_message is {} then
display dialog "Please select a message first and then run this script." with icon 1
return
end if
make new attachment at end of new_message with properties {file:theAttachment}
open new_message
end tell

This script is a merge of several threads I've read on in this forum. This script
leads to the following issue:

attach:545:623: execution error: Microsoft Outlook got an error: Can’t make "" into type specifier. (-1700)

which I can't pinpoint why is happening. File is clearly detected, new_message is clearly selected as I can open it when I remove the line in the script regarding making the new attachment. This line making the new attachment
is triggering the error, not sure why.

One note: this script worked once, I ended up with the attachment on the opened email. But only once, since then I've not been able to run it successfully, I get this error each time.

Thanks for any insights!
 
Try starting with something simple in the ScriptEditor app.
Ex:
AppleScript:
set theAttachment to choose file
tell application "Microsoft Outlook"
set new_message to item 1 of selection
make new attachment at end of new_message with properties {file:theAttachment}
end tell
 
Try starting with something simple in the ScriptEditor app.
Ex:
AppleScript:
set theAttachment to choose file
tell application "Microsoft Outlook"
set new_message to item 1 of selection
make new attachment at end of new_message with properties {file:theAttachment}
end tell
Did that, works very well, no issues. There is something about opening an existing message and attaching to it that trips the script. Not sure what.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.