I would like to import images from Apple Mail directly into Aperture. I found a script called Setup Mail Image Attachment Workflow but all it does is move the image to the Downloads folder and open
Aperture if it is not running and that is all. The image just stays in the Downloads folder. Also, this script is supposed to add IPTC metadata but it does not do this either. I am not familiar with scripting so not sure what may need to be edited to do what I want it to do. Can Aperture Assistant be configured to do this? Thanks, Mark
Aperture Assistant can't do this, but if you post the script I may be able to see where it's not working.
Thanks,
Ian
Hi Ian, here is the script:
property subject_placeholder : ""
property content_placeholder : ""
property project_name : "Email Attachments"
using terms from application "Mail"
on perform mail action with messages these_messages for rule this_rule
-- LOCATE THE DEFAULT MAIL DOWNLOADS FOLDER
set the destination_folder to my get_downloads_folder()
-- PROCESS THE MESSAGES PASSED TO THIS HNDLER
set the image_records to {}
tell application "Mail"
repeat with i from 1 to the count of these_messages
set this_message to item i of these_messages
-- GET THE SENDER OF THIS MESSAGE
set this_sender to the sender of this_message
-- GET SUBJECT AND CONTENT OF MESSAGE
try
set this_subject to (subject of this_message) as Unicode text
if this_subject is "" then error
on error
set this_subject to the subject_placeholder
end try
try
set this_content to (every character of content of this_message) as Unicode text
if this_content is in {"", "?"} then error
on error error_message
set this_content to the content_placeholder
end try
-- PROCESS ANY ATTACHMENTS
tell this_message
set these_attachments to every mail attachment
set image_counter to 1
repeat with z from 1 to the count of these_attachments
set this_attachment to item z of these_attachments
-- LOOK FOR IMAGE ATTACHMENTS
if the MIME type of this_attachment begins with "image" then
set this_name to the name of this_attachment
-- CHECK TO SEE IF A FILE WITH THAT NAME ALREADY EXISTS
tell application "Finder"
if (exists document file this_name of the destination_folder) then
set this_item to ((destination_folder as Unicode text) & this_name) as alias
copy my derive_filename(this_item, "", "-", "") to {target_filename, target_HFSpath}
else
set target_HFSpath to ((destination_folder as Unicode text) & this_name)
end if
end tell
-- DOWNLOAD AND SAVE IMAGE FILE
with timeout of 1800 seconds
save this_attachment in file target_HFSpath
end timeout
set this_image_file to (target_HFSpath as alias)
-- IMPORT IMAGE FILE INTO APERTURE
try
tell application "Aperture"
activate
if not (exists project project_name of library 1) then
make new project at beginning of projects of library 1 with properties {name:project_name}
end if
with timeout of 1800 seconds
set the import_results to (import this_image_file into project project_name of library 1)
end timeout
set this_image to item 1 of the import_results
-- APPLY IPTC TAGS USING MAIL SUBJECT, CONTENT, AND SENDER
tell this_image
if this_subject is not "" then
make new IPTC tag with properties {name:"Headline", value:this_subject}
end if
if this_content is not "" then
make new IPTC tag with properties {name:"Caption/Abstract", value:this_content}
end if
make new IPTC tag with properties {name:"Source", value:this_sender}
end tell
end tell
set image_counter to image_counter + 1
end try
end if
end repeat
end tell
end repeat
end tell
end perform mail action with messages
end using terms from
on derive_filename(this_item, new_extension, increment_separator, target_folder)
-- A sub-routine used for deriving the name and path of a new file using the name of an existing file
-- Pass in file ref in alias format, the new name extension, an increment separator, and any target directory (in alias format)
-- Name and HFS path for new file are returned. The name is incremented if a file exists in the target location.
-- Pass a null string for the target directory to use the item's parent directory
-- Pass a null string for the new name extension to use the item's current name extension
tell application "Finder"
if target_folder is "" then
set the target_folder to the container of this_item
end if
set the file_name to the name of this_item
set file_extension to the name extension of this_item
if the file_extension is "" then
set the trimmed_name to the file_name
set extension_separator to ""
else
set the trimmed_name to text 1 thru -((length of file_extension) + 2) of the file_name
set extension_separator to "."
end if
if the new_extension is "" then
set target_name to file_name
set target_extension to file_extension
else
set target_extension to new_extension
set target_name to (the trimmed_name & extension_separator & target_extension) as Unicode text
end if
if (exists document file target_name of target_folder) then
set the name_increment to 1
repeat
set the new_name to (the trimmed_name & increment_separator & (name_increment as Unicode text) & extension_separator & target_extension) as Unicode text
if not (exists document file new_name of the target_folder) then
set the target_HFSpath to ((target_folder as Unicode text) & new_name)
return {new_name, target_HFSpath}
else
set the name_increment to the name_increment + 1
end if
end repeat
else
set the target_HFSpath to ((target_folder as Unicode text) & target_name)
return {target_name, target_HFSpath}
end if
end tell
end derive_filename
on get_downloads_folder()
if system version of (system info) comes after "10.5" then
set downloads_folder to (path to downloads folder)
else
set the downloads_path to (do shell script "defaults read com.apple.mail MailDownloadsPath")
if the the downloads_path begins with "~" then
set this_path to the POSIX path of (path to home folder)
set the full_path to this_path & (text 3 thru -1 of the downloads_path)
set the downloads_folder to full_path as POSIX file as alias
else
set the downloads_folder to full_path as POSIX file as alias
end if
end if
return the downloads_folder
end get_downloads_folder