December 7, 2009

Launch Apple Mail

Surround SCM

Works with Surround SCM 2010 and later

Will not work with Surround SCM 2009 and earlier

This is a Mac version of the Launch Outlook example. In this example, we'll use Applescript to attach the files. The AppleScript is a little more complicated, as we have to handle the various ways that the results can be passed in (see the original article for the details.)
tell application "Mail"
	set numfiles to (system attribute "SSCM_NUMFILES" as string)
	set fileCount to (numfiles as number)
	if fileCount > 0 then
		set theMessage to make new outgoing message with properties {visible:true}
		if fileCount = 1 then
			set localPath to (system attribute "SSCM_LOCALFILE" as string)
			tell content of theMessage
				make new attachment with properties {file name:localPath} at after last paragraph
			end tell
		else if fileCount = 2 then
			set prevTIDs to AppleScript's text item delimiters
			set AppleScript's text item delimiters to " and /"
			set fileList to text items of (system attribute "SSCM_LOCALFILELIST" as string)
			set AppleScript's text item delimiters to prevTIDs
			tell content of theMessage
				make new attachment with properties {file name:first item of fileList} at after last paragraph
				make new attachment with properties {file name:last item of fileList} at after last paragraph
			end tell

		else
			set prevTIDs to AppleScript's text item delimiters
			set AppleScript's text item delimiters to ", "
			set fileList to text items of (system attribute "SSCM_LOCALFILELIST" as string)
			set AppleScript's text item delimiters to prevTIDs
			repeat with fileItem in fileList
				tell content of theMessage
					make new attachment with properties {file name:fileItem} at after last paragraph
				end tell
			end repeat
		end if
		activate
	else
		display dialog "You must have at least one file selected"
	end if
end tell