Entourage Attachment Reminder

Hey everyone, I’ve been going through forums and reference for a bit and haven’t been able to find something that already exists. Here’s the basic concept:

  1. Send button clicked
  2. AppleScript gets triggered
  3. Message scanned for “attach”,“file”,etc.
  4. If one or more of the words are found, continue – else, send message
  5. Prompt user: “Did you remember your attachment?”
  6. If yes, send – if no, cancel sending

The other option would be a trigger that runs the script and sends if criteria is true:

  1. Shortcut / menu / hotkey triggers AppleScript
  2. Message scanned for “attach”,“file”,etc.
  3. If one or more of the words are found, continue – else, send message
  4. Prompt user: “Did you remember your attachment?”
  5. If yes, send – if no, exit.

Anyone know where to start with this?

Here’s what I’ve come up with so far:

tell application "Microsoft Entourage"
	if class of the front window is draft window then
		set theWindow to the front window
		save theWindow
		set theMsg to displayed message of theWindow
		close theWindow
	else
		beep
		display dialog "This script only works with a new or draft message open in its own window." buttons {"OK"} default button 1 with icon 0
		return
	end if
	
	set thePara to the paragraphs of theMsg
	set remindAttach to false
	repeat with msgLine in thePara
		set msgLine to msgLine as text
		if msgLine contains "attach" then
			set remindAttach to true
		end if
	end repeat
	
	if remindAttach is true then
		display dialog "It appears you wanted to send an attachment. Have you already attached it?" with icon caution buttons ["Yes", "Cancel"] default button 2
		if button returned of result is "Yes" then
			send theMsg
		end if
	end if
	
end tell

So it appears I like talking to myself, but I’ve finally completed the script. It took about 2 hours which is not bad for my second AppleScript ever. If you’re going to use the script below, I’d appreciate my reference comments be intact.

-- Created by Ahmed Sagarwala (am [at] artform .dot. ca)
-- Oct 23, 2008 -=- Version 1.0 stable
-- http://www.artform.ca/
-- ======================
-- Thanks to Paul Berkowitz for posting their AppleScripts online!

tell application "Microsoft Entourage"
	-- Get your focus on
	activate
	
	-- Make sure we're working with a message window
	if class of the front window is draft window then
		-- Setup variables
		set theWindow to the front window
		set theText to the content of theWindow
		set thePara to the paragraphs of theText
		-- Default to false until proven guilty!
		set remindAttach to false
		
		-- Loop through each line and check for the string "attach"		
		repeat with msgLine in thePara
			set msgLine to msgLine as text
			set searchVar to offset of "attach" in msgLine
			-- See if the attach was found
			if searchVar is greater than 0 then
				set remindAttach to true
			end if
		end repeat
		
		-- An attachment is needed
		if remindAttach is true then
			beep
			display dialog "It appears you wanted to send an attachment. Have you already attached it?" with icon caution buttons {"Yes", "No"} default button 2
			-- User wants to send the message
			if button returned of result is "Yes" then
				send theWindow
			else
				return -- Cancel everything and allow for attachment
			end if
			
		else
			send theWindow -- No attachment was needed, sending by default
		end if
		
		-- Problem: we weren't working with a message window
	else
		beep
		display dialog "This script only works with a new or draft message open in its own window." buttons {"OK"} default button 1 with icon 0
		return
	end if
	
end tell

Feedback is also appreciated. :cool:

Model: MacBook Pro (2.5 GHz | 4GB RAM | Leopard, XP, Ubuntu 8)
AppleScript: 2.0.1
Browser: Firefox 3.0.1
Operating System: Mac OS X (10.5)

More than the functionality of the (self-explanatory) script, it puzzles me how you 'd want to trigger it.
How would you intercept the obvious hit of the “send” button ?

Found this while searching for something else and since it is probably out of date and you’ve probably learned a lot since, I won’t say much, just:

– no need to loop thru paragraphs or use offsets, you can just use:

if theText contains "attach" then

– why not give the option to choose the file and actually attach the file rather than cancel?

make new attachment at theWIndow with properties {file:ffile}

Great script, thank you ! I’ve introduced a couple of amendments:

  1. For multilingual users: added equivalents of “attach” in Italian, Danish and French besides English. Of course, anyone can change the languages at deemed necessary.

  2. Inversed Yes and No buttons as default (those who send 1 mail out of 10 with an attachment are more likely to forget)

  3. “No” button acts as “Cancel”, i.e. can be activated with the Esc key.



-- Created by Ahmed Sagarwala (am [at] artform .dot. ca)
-- Oct 23, 2008 -=- Version 1.0 stable
-- http://www.artform.ca/
-- ======================
-- Thanks to Paul Berkowitz for posting their AppleScripts online!

tell application "Microsoft Entourage"
	-- Get your focus on
	activate
	
	-- Make sure we're working with a message window
	if class of the front window is draft window then
		-- Setup variables
		set theWindow to the front window
		set theText to the content of theWindow
		set thePara to the paragraphs of theText
		-- Default to false until proven guilty!
		set remindAttach to false
		
		
		if theText contains "attach" then
			set remindAttach to true
			
		else if theText contains "allegat" then
			set remindAttach to true
			
		else if theText contains "vedhæft" then
			set remindAttach to true
			
		else if theText contains "joint" then
			set remindAttach to true
			
		end if
		
		
		-- An attachment is needed
		if remindAttach is true then
			beep
			display dialog "It appears you wanted to send an attachment. Have you already attached it?" with icon caution buttons {"Yes", "No"} default button 1 cancel button 2
			-- User wants to send the message
			if button returned of result is "Yes" then
				send theWindow
			else
				return -- Cancel everything and allow for attachment
			end if
			
		else
			send theWindow -- No attachment was needed, sending by default
		end if
		
	end if
	
end tell


Model: MacBook Pro
AppleScript: 2.1.2
Browser: Firefox 6.0.2
Operating System: Mac OS X (10.6)