Droplet for Outlook Attachments

Hi

I’ve created a droplet so that when I drop a file on there, it adds the file as an attachment to a new email message in Outlook (on the mac), the script also takes the filename and adds it to the subject line and adds a default email message that includes a reference to the file.


--Creates a new mail message when a file is dropped on the script droplet, the subject is the filename--

on open Dropped_File
	tell application "Finder"
		set NameOfFile to (name of (info for Dropped_File))
		set myFile to Dropped_File as alias
		--display dialog NameOfFile
	end tell
	
	
	tell application "Microsoft Outlook"
		set mySubject to NameOfFile as text
		set myContent to "<p style=font-family:Calibri>Hi</p><p style=font-family:Calibri>Attached is a LoRes PDF for job " & NameOfFile & "<p style=font-family:Calibri>Thanks</p>"
		set myAttachment to Dropped_File
		set myMsg to make new outgoing message with properties {subject:mySubject, content:myContent}
		tell myMsg
			make new attachment with properties {file:myFile}
		end tell
		open myMsg
		
	end tell
	
end open

I want to expand the droplet a bit more.

The files I drop on there have a consistent filename structure: 11-CH-16 Job Description (100x100)_v1.pdf - (so this is a job number made up of 2 digits hyphen 2 characters hyphen 2 or 3 characters; then a job description; a size within brackets; and then an underscore and version number).

So firstly I’d like the script to just add the job number to the subject line, so I need to implement some GREP into the script to pull this from the filename. I’m stuck on this bit. I know the GREP would be something like [\l\u]{2}±\d{2}±\d{1,4} but I’m not sure how to get this into the script

The second thing I like the droplet to do is accept multiple files being dropped onto it. The multiple files would all have the same job number.

Any help would be great

Thanks in advance

David

Hi David,

Welcome to MacScripter! :slight_smile:

The script below assumes there is a space in between the job number, and the description, as per your original post.
Can you confirm whether or not that’s the case.


on open Dropped_Files
	
	tell application "Finder" to set NameOfFile to (name of (info for item 1 of Dropped_Files))
	
	set {atid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, space}
	set mySubject to text item 1 of NameOfFile
	set AppleScript's text item delimiters to atid
	
	
	tell application "Microsoft Outlook"
		
		set myContent to "<p style=font-family:Calibri>Hi</p><p style=font-family:Calibri>Attached is a LoRes PDF for job " & NameOfFile & "<p style=font-family:Calibri>Thanks</p>"
		set myAttachment to Dropped_Files
		set myMsg to make new outgoing message with properties {subject:mySubject, content:myContent}
		
		tell myMsg
			repeat with thisItem in Dropped_Files
				tell application "Finder" to set thisOne to thisItem as alias
				make new attachment with properties {file:thisOne}
			end repeat
		end tell
		
		open myMsg
		
	end tell
	
end open

You’ll need to save the above as an application.

HTH

Yeah, that’s correct there’s a space after the job number.

I’ve tried your script and it works perfectly, with both single and multiple files.

Thanks for the help.

Glad to learn it works ok. :slight_smile:

I wanted to check about the space, after the job number, because it’s used to split the filename of the pdf.