Page 1 of 1

Attach File to Outlook Email

PostPosted: Wed Jan 02, 2019 7:01 pm
by HackerJL
Ive been playing with some automation, and tying it into Outlook, since Outlook disabled automator functions. I figured go hazel and never go back. Im having some issues with the AppleScript and attaching theFile. See below:
tell application "Microsoft Outlook"
set newMessage to make new outgoing message with properties {subject:"Invoices from Me"}
make new recipient at newMessage with properties {email address:{name:"Jim Shank", address:"jim.shank@example.com"}}
tell newMessage
repeat with aFile in SelectedItems -- the loop through all selected items
make new attachment with properties {file:theFile}
end repeat
end tell
open newMessage
get newMessage
end tell
return input


Any help would be appreciated.

Re: Attach File to Outlook Email

PostPosted: Thu Jan 03, 2019 10:21 am
by Mr_Noodle
What issues are you seeing exactly? Does the script work outside of Hazel?

Re: Attach File to Outlook Email

PostPosted: Thu Jan 03, 2019 3:47 pm
by HackerJL
Im seeing no attachment.

Outside of this, I took this from an automator script where I was playing until I thought hazel was better suited based on file triggers.

The version from automator is here:
on run {input, parameters}
set SelectedItems to input
tell application "Finder" to set fileName to name of first item of SelectedItems
tell application "Microsoft Outlook"
set newMessage to make new outgoing message with properties {subject:"Invoices from me"}
make new recipient at newMessage with properties {email address:{name:"Jim Shank", address:"jim.shank@example.com"}}
tell newMessage
repeat with aFile in SelectedItems -- the loop through all selected items
make new attachment with properties {file:aFile}
end repeat
end tell
open newMessage
get newMessage
end tell
return input
end run

Re: Attach File to Outlook Email

PostPosted: Fri Jan 04, 2019 1:31 pm
by Mr_Noodle
Again, though, does the script work outside of Hazel?

The script itself looks like it's relying on selected items. Probably not a good idea to have it rely on the current state of the UI at the time the script is run.