Anyone familiar with Sal Soghoian's Applescript Aperture Hot Folder.app?
It works great, except it doesn't cause Aperture to import video files from my Canon 5D Mark II. Any ideas?
Thanks,
Eric
property project_name : missing value
property script_name : "Aperture Hot Folder.scpt"
property right_arrow : true
global target_folder, display_quit, project_references, folder_path, project_paths, project_IDs, project_ID, import_method
on run
set the icon_file to (path to resource "applet.icns")
set display_quit to false
display dialog "This script will import photos into Aperture from a folder designated by camera software as the destination for images downloaded from a tethered camera." & return & return & "Click the “Continue” button to setup this script by selecting an existing camera destination folder and choosing an Aperture project to receive the image files downloaded from the tethered camera into the chosen folder." with title "Aperture Hot Folder v1.5" buttons {"Stop", "Continue"} default button 1 with icon icon_file
if the button returned of the result is "Stop" then tell me to quit
-- LAUNCH APERTURE IF IT IS NOT ALREADY RUNNING
-- open Aperture if it is not running
set the creator_code to "fstp"
-- check to see if app is already open
tell application "System Events"
set the app_IDs to the creator type of every process
end tell
if app_IDs does not contain the creator_code then
-- check for app file
try
tell application "Finder"
set this_app to (application file id creator_code) as Unicode text
end tell
ignoring application responses
tell application this_app to launch
end ignoring
on error error_message
activate
display dialog "Aperture is not installed on this computer." with title "Application Launch Error" with icon stop buttons {"Stop"} default button 1
tell me to quit
end try
end if
-- check to see if the app is open
set timeout_value to 600
repeat with i from 1 to timeout_value
if i is timeout_value then
activate
display dialog "This script timed out waiting for Aperture to launch." & return & return & "Make sure Aperture is open before running this script." with title "Application Launch Error" with icon stop buttons {"Stop"} default button 1
tell me to quit
end if
tell application "System Events"
set the app_IDs to the creator type of every process
end tell
if app_IDs contains the creator_code then
delay 2
exit repeat
else
delay 1
end if
end repeat
-- DETERMINE THE HOT FOLDER USED BY THE CAMERA SOFTWARE
try
activate
set the target_folder to (choose folder with prompt "Select the chosen download folder used by the camera software:")
on error
tell me to quit
end try
set the folder_action_script to (path to resource script_name)
set the folder_action_folder to (path to Folder Action scripts folder from user domain)
tell application "Finder"
-- check to see if script is in Folder Action Scripts folder, if not duplicate
if not (exists document file script_name of the folder_action_folder) then
set the action_script to (duplicate the folder_action_script to the folder_action_folder) as alias
else
set the action_script to (document file script_name of folder_action_folder) as alias
end if
end tell
tell application "System Events"
set folder actions enabled to true
-- attach the script to the hot folder if it is not already attached
if (the attached scripts target_folder) does not contain action_script then
attach action to the target_folder using the action_script
end if
end tell
-- CREATE A DESTINATION PROJECT
tell application "Aperture"
activate
try
display dialog "Do you want to import images into a new project or an existing project?" buttons {"Cancel", "Existing", "New"} default button 3 with icon icon_file
set the project_action to the button returned of the result
on error
tell me to quit
end try
if the project_action is "New" then
try
repeat
display dialog "Enter the name for a new project to contain the imported images:" default answer "" with title "Create Import Project" with icon icon_file
set the project_name to the text returned of the result
if the project_name is not "" then exit repeat
end repeat
on error
tell me to quit
end try
try
tell library 1
set this_project to make new project with properties {name:project_name}
end tell
-- Aperture will make a numbered version if conflict exists so get the name
set the project_name to the name of this_project
set project_ID to the id of this_project
on error
display dialog "There was a problem creating a new project." & return & return & "Make sure Aperture is fully launched and ready to use before running this script." buttons {"Stop"} default button 1 with icon stop
tell me to quit
end try
else
my generate_projectlist()
set this_path to (choose from list project_paths) as Unicode text
if this_path is "false" then tell me to quit
repeat with i from 1 to the count of project_paths
if this_path is (item i of the project_paths) then
set the project_ID to (item i of the project_IDs)
exit repeat
end if
end repeat
end if
end tell
-- PROMPT FOR IMPORT METHOD
tell application "Aperture"
activate
set this_version to the version
if this_version is greater than or equal to "1.5" then
try
display dialog "Do you want to import the image files into the Aperture library or leave them where they are and import references to the files?" buttons {"Cancel", "References", "Library"} default button 3 with icon icon_file
set the import_method to the button returned of the result
on error
tell me to quit
end try
else
set the import_method to "Library"
end if
end tell
-- CONFIRMATION
tell application "Aperture"
activate
display dialog "Setup is complete, this applet will stay open and running." & return & return & "To stop this script, make the script applet the frontmost application and choose “Quit” from its Application menu." with title "Setup Completion Dialog" with icon icon_file buttons {"OK"} default button 1 giving up after 15
end tell
set display_quit to true
end run
on quit
if display_quit is true then
activate
display dialog "Do you want to stop this script and disable auto-importing from the chosen hot folder?" buttons {"No", "Yes"} default button 2 with title "Quit Confirmation" with icon caution
if the button returned of the result is "Yes" then
try
tell application "System Events"
repeat with i from 1 to the count of (attached scripts of target_folder)
remove action from the target_folder using action number i
end repeat
end tell
end try
set the prefs_folder to (path to preferences folder from user domain) as Unicode text
try
set the prefs_file to (the prefs_folder & "com.apple.Aperture.HotFolder.plist") as alias
tell application "Finder" to delete the prefs_file
end try
continue quit
error number -128
else
tell application "Aperture" to activate
end if
else
continue quit
error number -128
end if
end quit
on idle
set the prefs_folder to (path to preferences folder from user domain) as Unicode text
try
set the prefs_file to (the prefs_folder & "com.apple.Aperture.HotFolder.plist") as alias
on error -- "NO PLIST"
return 2
end try
tell application "System Events"
set this_plist_file to property list file (POSIX path of the prefs_file)
tell this_plist_file
if the (count of property list items) is 0 then
return 2
else
set the item_identifier to the name of property list item 1
set the item_path to the value of property list item 1
try
set the target_file to item_path as POSIX file as alias
repeat
set this_info to the info for the target_file
set size_A to the size of this_info
delay 2
set this_info to the info for the target_file
set size_B to the size of this_info
if size_A is equal to size_B and size_B is not 0 then
try
tell application "Aperture"
-- activate
if import_method is "Library" then
set this_image to import target_file into (project id project_ID) -- by copying
else
set this_image to import target_file into (project id project_ID) by referencing
end if
end tell
end try
do shell script ("defaults delete com.apple.Aperture.HotFolder " & item_identifier)
if right_arrow is true then
my advance_selection()
end if
delay 2
exit repeat
end if
end repeat
return 2
on error x
-- say x
return 2
end try
end if
end tell
end tell
end idle
on advance_selection()
tell application "System Events"
-- if Aperture is the frontmost applicaiton then hit the right arrow key to advance to the next image
set the application_identifier to the creator type of first process whose frontmost is true and visible is true
if the application_identifier is "fstp" then
key code 124
end if
end tell
end advance_selection
on generate_projectlist()
tell application "Aperture"
tell library 1
set the project_references to {}
repeat with i from 1 to the count of projects
set the end of the project_references to {name of project i, id of project i}
end repeat
set folder_path to ""
repeat with i from 1 to the count of folders
my find_projects(folder i)
end repeat
end tell
end tell
set the project_paths to {}
set the project_IDs to {}
repeat with i from 1 to the count of the project_references
copy item i of the project_references to {project_path, project_ID}
set the end of the project_paths to the project_path
set the end of the project_IDs to the project_ID
end repeat
end generate_projectlist
on find_projects(this_folder)
tell application "Aperture"
-- construct path to this folder
if folder_path is not "" then
set folder_path to folder_path & " > " & the (name of this_folder)
else
set the folder_path to the (name of this_folder)
end if
-- look for projects in this folder
repeat with i from 1 to the count of projects of this_folder
tell this_folder
set the end of the project_references to {folder_path & " > " & (name of project i), id of project i}
end tell
end repeat
-- look for folders in this folder
if the (count of folders of this_folder) is 0 then
-- no more folders to search
set the folder_path to ""
else
repeat with i from 1 to the count of folders of this_folder
my find_projects(folder i of this_folder)
end repeat
end if
end tell
end find_projects