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


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: 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 | # ]