Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Mail lots of files to one recipient in multiple messages Apps
Whenever I want to email some pictures from iPhoto, it composes one huge message with all the pictures in it. What I wanted was a way to send each picture in a separate mail. So I whipped up the following AppleScript (my first!) to send a selection of files (the Finder selection, in fact), all to the same recipient.

It takes an email address, and a subject line and composes messages with subjects "blablabla (x/X)" where X is the total number of files. Maybe this is useful to someone else. I know I looked high and low for this.

Read the rest of the hint for the script...


tell application "Finder"
  if selection is not {} then
    set itemList to selection
    set itemNumber to count of itemList
  else
    display dialog "No files selected." buttons {"Cancel"} ¬
      default button 1 giving up after 15 with icon 2
  end if
end tell

tell application "Mail"
  
  set addrVar to text returned of (display dialog ¬
    "Enter destination address:" default answer "hello@parents.org")
  set subjectvar to text returned of (display dialog ¬
    "Enter subject line:" default answer "Pictures")
  display dialog "Number of files: " & itemNumber
  
  repeat with i from 1 to count items in itemList
    
    tell application "Finder"
      set the target_file to (document file ¬
        ((contents of item i of itemList) as string)) as alias
      set bodyvar to the name of target_file
    end tell
    
    set composeMessage to (make new outgoing message)
    
    tell composeMessage
      make new recipient at beginning of to recipients ¬
        with properties {address:addrVar}
      set the subject to subjectvar & " (" & (i as string) & ¬
        "/" & itemNumber & ")"
      set the content to bodyvar
      tell content
        make new attachment with properties {file name:target_file} ¬
          at after the last word of the last paragraph
      end tell
    end tell
    
    send composeMessage
    
  end repeat
  
end tell
[robg adds: I sent the submitted code to an experienced AppleScripting friend of mine, and he made a few minor changes to make this script work a bit better. He also adds that if you find the dialog box with the item count to be superfluous, it can be safely commented out.]
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[4,275 views]  

Mail lots of files to one recipient in multiple messages | 10 comments | Create New Account
Click here to return to the 'Mail lots of files to one recipient in multiple messages' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Mail lots of files to one recipient in multiple messages
Authored by: gdsimms on Mar 24, '04 01:26:14PM

This is definitely useful to me, since I have tons of relatives asking for pictures of my new baby mailed to their 5MB free email accounts. Now instead of bouncing all of the pictures in the whole message, I can just send a wad of emails and then wait for individual bounces.... ;-)



[ Reply to This | # ]
Mail lots of files to one recipient in multiple messages
Authored by: Fofer on Mar 24, '04 02:30:38PM

If you do it from iPhoto, you can tell it to send a "small" version of the pic... these are usually ~30k or so and perfect for email.



[ Reply to This | # ]
Mail lots of files to one recipient in multiple messages
Authored by: gdsimms on Mar 24, '04 05:36:40PM

I begin with that, then I get the requests back for full size versions of some subset of pics. I'm considering just mailing monthly CDROMs.



[ Reply to This | # ]
Mail lots of files to one recipient in multiple messages
Authored by: gdsimms on Mar 24, '04 01:54:54PM

Any chance this can be modified to pick photos directly in iPhoto instead of Finder?



[ Reply to This | # ]
Mail lots of files to one recipient in multiple messages
Authored by: koncept on Mar 25, '04 02:52:05AM
This should do it... Sorry about the length...

property mailtoEmail : "user@domain.com" --change this to specify a default address
property subject : "An iPhoto for you: "
property resize : true -- will not affect original images  (true | false).
property scale : 640 -- if resize, how wide to scale?
property includeFileName : true -- if true, the attachment name will appear in the message (true | false)

on scaleAndRet(obj)
  tell application "Image Events"
    set dataObj to open obj
    scale dataObj to size |scale|
    save dataObj in obj with icon
    close dataObj
  end tell
  tell application "Finder" to return ¬
    {name of obj, POSIX path of obj}
end scaleAndRet

on retPosix(thisPath)
  return POSIX file thisPath
end retPosix

tell application "iPhoto"
  set photoHash to {}
  set sel to selection
  set cnt to count (sel)
  try
    repeat with i from 1 to cnt
      set end of photoHash to ¬
        {image filename, image path} ¬
          of item i in sel
    end repeat
  on error
    beep (2)
    set str to "Please select some photos in iPhoto's "
    set str to str & "window and run me again."
    display dialog str with icon stop
    return false
  end try
  set cnt to count (photoHash)
  if resize then
    tell application "Finder"
      set resizeObjHash to {}
      set tmpFld to (path to temporary items folder)
      set rand to (random number from 10000 to 99999) as string
      if not (exists folder rand of tmpFld) then ¬
        make new folder at tmpFld with properties {name:rand}
      display dialog "Resizing images..." buttons {"•"} ¬
        default button 1 giving up after 1 with icon note
      repeat with i from 1 to count (photoHash)
        set thisPath to item 2 of item i in photoHash
        set pCopy to my retPosix(thisPath)
        set obj to duplicate pCopy to folder rand of tmpFld
        set end of resizeObjHash to (my scaleAndRet(obj as alias))
      end repeat
      set photoHash to resizeObjHash
    end tell
  end if
  repeat with i from 1 to cnt
    set thisName to item 1 of item i in photoHash
    set thisPath to item 2 of item i in photoHash
    tell application "Mail"
      activate
      set mailAddy to text returned of (display dialog ¬
        "Enter email address to send to:" default answer mailtoEmail)
      set sub to text returned of (display dialog ¬
        "Enter subject of message (" & i & " of " & cnt & ")"¬
          default answer |subject| & thisName)
      set nm to make new outgoing message
      tell nm
        set subject of nm to sub
        make new to recipient at end of ¬
          to recipients with properties {address:mailAddy}
        get properties of nm
        if includeFileName then
          set c to content
          set content to return & "(* attachment: "& ¬
            thisName & " *)" & return & c
        end if
        tell content
          make new attachment with properties ¬
            {file name:thisPath} at¬
              before the first word of the first paragraph
        end tell
        send nm
      end tell
    end tell
  end repeat
end tell


[ Reply to This | # ]
Mail lots of files to one recipient in multiple messages
Authored by: koncept on Mar 25, '04 02:56:51AM
If you have problems with my script, try editing it so that lines following "¬" symbols are all on one line: Example:
this spans¬
  two lines
Change to:
this spans two lines


[ Reply to This | # ]
Mail lots of files to one recipient in multiple messages
Authored by: gdsimms on Mar 25, '04 03:30:54PM

I got it working. Thanks. With that script and the original, I think I can piece together something that would automate my family picture distribution nicely.



[ Reply to This | # ]
Mail lots of files to one recipient in multiple messages
Authored by: maddys_daddy on Mar 27, '04 01:59:46AM

koncept,
Your script is exactly what I need, but I can't get it to work. It makes it as far as the "Resizing Images..." dialog, but after that closes, it does nothing. FWIW, I tried it both with the little "sideways L" and without, just as you posted above. No dice. Any ideas why this isn't working? How can I assist in the troubleshooting. I really want this to work!



[ Reply to This | # ]
Mail lots of files to one recipient in multiple messages
Authored by: jmcdonnell on Mar 25, '04 12:10:08PM

I would think an easier way to accomplish this would be to make a web page using iPhoto and .Mac. Then email the web address to all of the people that you want to notify. That way if the receiver of the email only wants 3 of the 50 pictures on your web page he/she only has to download the 3 pictures he/she wants not all 50.



[ Reply to This | # ]
Mail lots of files to one recipient in multiple messages
Authored by: maddys_daddy on Mar 27, '04 01:39:02AM

That's a nice idea, jmc, but not all of us have a .Mac account. It's a great hint, nevertheless.
Besides, this hint is rather invaluable if you're talking about files other than photos. Like the many pdf's that I have to send out regularly to clients. Instead of one big 3MB e-mail, now they get about 6 500KB e-mails. Many e-mail servers bounce large attachments.



[ Reply to This | # ]