• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Requesting help with saving 'Mail' attachments, please
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Requesting help with saving 'Mail' attachments, please


  • Subject: Re: Requesting help with saving 'Mail' attachments, please
  • From: Brian Christmas <email@hidden>
  • Date: Tue, 16 Dec 2014 13:44:08 +1100

It’s all OK, thanks.

Turned out I had to re-boot to refresh Yosemite, then Mail worked alright. Merely quitting and restarting Mail wasn’t enough.

The slightly modified script is below, if anyone wants to save Mail attachments in future. 

I’ve altered the renaming to [NAME]  [NUMBER]  [NAME EXTENSION] instead of [NUMBER]  [NAME & EXTENSION].

Regards

Santa

 
From: Brian Christmas <email@hidden>
Subject: Requesting help with saving 'Mail' attachments, please
Date: 16 December 2014 11:06:36 am AEDT
To: applescriptobjc-dev <email@hidden>

G’day scripters

I have a method that worked in Mountain Lion, but refuses to work in Yosemite, and I cannot for the life of me work out why.

The script below sums it up. I get an error -10000, Apple Event handler failed.

If anyone can guide me on what I’m doing wrong, I’d appreciate it, please.

Regards

Santa

property currentMailItem : {}
property holding_folder : ""
property printDateTimeName : "2014-12-15 102310Z"

set ptd to path to desktop

set temporaryFolderPath to ptd & "Temporary Printing" as text
set my holding_folder to (ptd & "Temporary Printing:" & my printDateTimeName) as text
set runForOz to true

tell application "Finder"
if not (exists folder temporaryFolderPath) then
try
make new folder at folder ptd with properties {name:"Temporary Printing"}
end try
end if
if not (exists folder (my holding_folder)) then
say "making folder"
make new folder at folder temporaryFolderPath with properties {name:my printDateTimeName}
end if
end tell
tell application "Finder"
say "Folder exists is " & (exists folder (my holding_folder)) as text
end tell

tell application "Mail"
set my currentMailItem to message 1 of mailbox "* items to store"
repeat with theAttachment in my currentMailItem's mail attachments
  set originalName to name of theAttachment
set x to 0
set addOnText to ""
#
# This 'repeat to set new Attachment name' is necessary because 'Mail' messages can 
# contain more than one Attachment with same name.
#
set theNameStart to characters 1 through ((offset of "." in originalName) - 1) of originalName as rich text
try
set theNameExtension to characters (offset of "." in originalName) through -1 of originalName as rich text
on error
set theNameExtension to "" # Folder
end try
repeat
  set savedAttachmentPath to (my holding_folder & ":" & theNameStart & addOnText & theNameExtension) as rich text
tell application "Finder"
  set existsFile to exists (item savedAttachmentPath)
end tell
  if existsFile then
set x to x + 1
  set addOnText to (" " & x) as rich text
else
  # 
# Use 'with replacing' to make absolutely sure of saving
#
try
save theAttachment in file savedAttachmentPath with replacing
on error errmsg number errnum
if runForOz then display dialog "Attachment saving error " & errmsg & " number = " & errnum
end try
tell application "Finder"
set y to 0
repeat
try
set y to y + 1
if y ≥ 40 then
set exitFlag to true
exit repeat
end if
  set exitFlag to (exists item savedAttachmentPath)
exit repeat
end try
tell current application to delay 0.1
end repeat
if exitFlag then
say "Existing"
exit repeat
end if
end tell
end if
end repeat
end repeat
end tell


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
applescriptobjc-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Requesting help with saving 'Mail' attachments, please (From: Brian Christmas <email@hidden>)

  • Prev by Date: Requesting help with saving 'Mail' attachments, please
  • Next by Date: Why O why is speech needed?
  • Previous by thread: Requesting help with saving 'Mail' attachments, please
  • Next by thread: Why O why is speech needed?
  • Index(es):
    • Date
    • Thread