I’ve been using Shanes code to save new files under 10.12.2 with great results, until I tried to handle os file name "MM Testing 12/20/16.pdf”.
which I supposed is to be expected. The code is below…
Are there any alterations I can make that will allow the use of a forward slash in a file name?
repeat with eachAttachment from 1 to my attachmentCounter
set theAttachment to item eachAttachment of attachmentList
tell application "Mail" to 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 thisChar to "."
set offSetText to (length of originalName) - (offset of thisChar in (reverse of text items of originalName as string))
set theNameStart to (characters 1 through offSetText of originalName) as Unicode text
try
set theNameExtension to (characters (offSetText + 1) through -1 of originalName) as text
on error
set theNameExtension to "" # Folder
end try
set exitFlag to false
#
repeat
try
set savedAttachmentPath to ((my holdingFolder) & theNameStart & addOnText & theNameExtension as Unicode text)
tell application "Finder"
set existsFile to exists (item savedAttachmentPath)
end tell
on error errmsg
tell application "System Events" to display dialog "subroutineOne internal repeat " & errmsg giving up after 20
end try
if existsFile then
set x to x + 1
set addOnText to (" copy " & x) as text
else
try
# NEW Code
set p to 100
set pathToFile to savedAttachmentPath as Unicode text
-- create file
set p to 101
set theFile to pathToFile as «class furl»
set p to 102
set fileRef to open for access theFile with write permission
set p to 103
close access fileRef
set p to 104
tell application "Mail"
set p to 105
tell theAttachment
set p to 106
save in theFile
end tell
end tell
exit repeat
on error errmsg number errnum
if errnum ≠ -10000 then
if my runForOz then tell application "System Events" to display dialog "Attachment saving error p = " & p & " " & errmsg & " number = " & errnum giving up after 20
set my attachmentMailFlag to "Errors found"
end if
exit repeat
end try
end if
end repeat
end repeat