Error with Automator WorkFlow

Hi

I am lost!

I am trying to use KM to allow me to attach selected files in Finder to an Outlook Mac (V16) message.

To attach one file I use the following Applescript which works in KM perfectly:

tell application "Finder" to set selectedItem to item 1 of (get selection)

set theAttachment to selectedItem as alias
set fileName to name of selectedItem

tell application "Microsoft Outlook"
   activate

   set newMessage to make new outgoing message with properties {subject:fileName}
   
   tell newMessage
      make new attachment with properties {file:theAttachment}
   end tell
   
   open newMessage
   get newMessage
   
end tell

What I wanted to do is to use the same Applescript but to be able to pass more than one file to the Applescript and attach those to an email. I looked high and low but could not find a way.

I then found a way to use Automator. If I create an Automator Service and use the following, it works perfectly. In KM using the service or a Workflow using the same code, I get an error and it doesn't work.

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:fileName}
      tell newMessage
         repeat with aFile in SelectedItems
            make new attachment with properties {file:aFile}
         end repeat
      end tell
      
      open newMessage
      
      get newMessage
   end tell
   
   return input
end run

Can you help?

Thanks

Andrew

On my system with Outlook 2011 the macro below works to start a new message with the files selected in Finder attached.

Keyboard Maestro 8.2.4 “Attach files to Outlook” Macro

Attach files to Outlook.kmmacros (1.4 KB)

1 Like

Hey Andrew,

Here's how to make that AppleScript work with multiple files.

-Chris


New Message with Selected Files in Finder v1.00.kmmacros (5.9 KB)

Thanks - just need to figure out how to have a subject automatically in the message.

Andrew

Chris - this is perfect!!! Thanks so much

1 Like