Hello,
I’m in need of some help on a script I need. This may be a fair amount of work so I 'm willing to pay a little for someone’s assistance. First some background on what I’m doing.
I’m a photographer and use an application called Capture One Pro to process our Raw files to TIFF and JPEG. When we start a new job in C1Pro we always name the job a specific way which is a Job Number and Client Name pair (i.e. 0000-00 ClientName) so C1Pro creates a folder by that name in our Work In Progress folder. Inside the job folder “0000-00 ClientName” C1Pro creates three folders (Captures, Processed and Trash). Inside of “Processed” C1Pro will create a folder called “Raw_Exports” in which our final high resolution files are placed.
I need to test for and create a new folder, if it doesn’t exist, then zip each item individually and move the zipped file to the “Delivered” folder.
***Here is an overview of what I need to accomplish.
- Select “Job Folder” via prompt and place in variable “jobFolder”
- Create variables that contain the paths to “Job Folder:Processed” and “Job Folder:Processed:Raw_Exports”
(variable names “processedFolder” and “exportsFolder” respectively) - Test for the existence of the folder “Delivered” which should be at “Job Folder:Processed:Delivered”
and create the folder if needed. then create variable for “Delivered” called deliveredFolder. - Get a list of every file in the folder “Raw_Exports”
- Get a list of every file in the “Delivered” folder
- Compare the lists and omit files that have been zipped and placed in the “Delivered” folder.
- Compress each item in “Raw_Exports”, excluding items already compressed, individually using ditto as zip
and do not keep parent - add “hr_” to the begining of each compressed filename and remove original extension (i.e. name.tif.zip
remove .tif) - Move each compressed file to the “Delivered” folder
- Temporarily rename the folder “Delivered” to (“Job_” & jobNumber) (i.e. Job_0000-00)
- Upload to webserver
- Rename folder back to “Delivered”
- Display completion Dialog
Here is the script I’ve been trying to get working
(* Select the job folder *)
choose folder with prompt "Choose a job folder to upload HiRes files to the web for:"
set jobFolder to result
set processedFolder to ((jobFolder as string) & "Processed") as alias
set exportsFolder to ((processedFolder as string) & "Raw_Exports") as alias
(* Test for Delivered folder and create if it doesn't exist*)
tell application "Finder"
if not (folder ((processedFolder as string) & "Delivered") exists) then
make new folder at processedFolder with properties {name:"Delivered"}
end if
set deliveredFolder to ((processedFolder as string) & "Delivered") as alias
set the destination_folder to deliveredFolder as alias
set the destination_directory to POSIX path of ¬
the destination_folder
end tell
(* NOT WORKING - Get list of items in processedFolder and compress each item individually.
also add hr_ to beginning of compressed file name and move compressed file to deliveredFolder *)
with timeout of 1000000 seconds
try
set fileNames to {}
tell application "Finder"
set all_files to every file of entire contents of folder exportsFolder
repeat with a_file in all_files
set end of fileNames to (quoted form of POSIX path of (a_file as Unicode text))
end repeat
--repeat the command to compress each item as an individual archive
repeat with a_file in all_files
--used to extract the name and location of the file
set itemProp to properties of a_file
--where the file is
set itemPath to quoted form of POSIX path of a_file
--where the compressed file should end up
set destFold to quoted form of POSIX path of deliveredFolder
--what the name of the file is
set itemName to name of a_file
set itemName to ("hr_" & itemName)
--do it, do it now
do shell script ¬
("ditto -c -k -X --rsrc " & itemPath & ¬
" " & destFold & "'" & itemName & "'" & ".zip")
set itemName to ("hr_" & itemName)
end repeat
end tell
on error errmsg
--should anything go wrong let the user know
display dialog errmsg
end try
end timeout
-- If someone can get it working through to this point I should be able to handle the rest
-- Most everything below here works
(* Extract client name and job number from jobFolder *)
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to " "
set clientName to every text item of (name of (info for jobFolder))
set jobNumber to first item of result
set clientName to (items 2 through -1 of clientName) as string
set AppleScript's text item delimiters to ASTID
set webFolder to ((jobFolder as string) & "Processed:Delivered") as alias
tell application "Finder" to set name of result to ("Job_" & jobNumber)
(* Upload via FTP using Transmit *)
set oldDelim to text item delimiters
set text item delimiters to " "
set the_server to "[url=ftp://ftp.webserver.com]ftp.webserver.com[/url]"
set the_user to "username"
set the_pass to "password"
set the_proto to "FTP"
set the_port to "21"
set base_path to "/server/path/to/clientfolders/"
set the_path to (base_path & clientName)
-- Make sure Transmit exists before anything else
tell application "Finder"
try
set transmitVersion to (get version of application file id "TrAn")
on error
return "Couldn't find Transmit"
end try
if transmitVersion does not contain "Transmit 3" then
return "Transmit 3 required"
end if
end tell
-- Find out if Transmit was already running, we'll use this later
tell application "System Events"
set wasRunning to name of every process whose name contains "Transmit"
end tell
-- Now work magic
tell application "Transmit"
-- Get the old value
set oldSuppressValue to (SuppressAppleScriptAlerts of application "Transmit")
-- Turn off alerts
set SuppressAppleScriptAlerts to true
-- Maybe make a new window
if (wasRunning is not {}) then
set myDoc to make new document
else
set myDoc to document 1
end if
set didConnect to false
set didChange to false
set didUpload to false
-- Tell the session what to do
set mySession to current session of myDoc
tell mySession
-- Try to connect to the server
if the_proto = "FTP" then
set didConnect to connect to (the_server) using port (the_port) as user (the_user) with password (the_pass) with connection type FTP
else if the_proto = "SFTP" then
set didConnect to connect to (the_server) using port (the_port) as user (the_user) with password (the_pass) with connection type SFTP
else if the_proto = "WebDAV" then
set didConnect to connect to (the_server) using port (the_port) as user (the_user) with password (the_pass) with connection type WebDAV
end if
if (didConnect = true) then
-- Try to change directories if requested
if (the_path is not "") then
set didChange to set their stuff to (the_path)
else
set didChange to true
end if
-- UPLOAD: Upload the files here
try
with timeout of 3600 seconds
upload item webFolder with resume mode resume
end timeout
set didUpload to "true"
end try
if (didUpload = false) then
error
end if
disconnect
end if
end tell
-- Error out if we need to, and don't close the window
if (didConnect = false) then
set SuppressAppleScriptAlerts to oldSuppressValue
return "Couldn't connect"
end if
if (didChange = false) then
set SuppressAppleScriptAlerts to oldSuppressValue
return "Couldn't set path"
end if
-- Set back to the old value
set SuppressAppleScriptAlerts to oldSuppressValue
-- Quit Transmit or Close the Window, depending on if it was running
if (wasRunning is {}) then
quit
else
tell myDoc
close
end tell
end if
set webFolder to ((jobFolder as string) & "Processed:Job_" & jobNumber) as alias
tell application "Finder" to set name of result to ("Delivered")
end tell
set text item delimiters to oldDelim
display dialog "The HiRes files for Job " & jobNumber & " have been uploaded to the " & clientName & " folder in the Client Area.
Would you like to go to the Client Folder now?" buttons {"No", "Yes"} default button 2
copy the result as list to {the button_pressed}
if button_pressed = "Yes" then
set the target_URL to "http://www.webserver.com/cgi-bin/ImageFolio31/imageFolio.cgi?direct=" & clientName & "/" & "Job_" & jobNumber
open location target_URL
end if
This script is probably messy as it has been pieced together from samples and tutorials and I’m obviously fairly new to Applescript at least anything of this magnitude. If this needs more explaining please contact me. I have placed a group of folders that can be downloaded that show the folder structure.
http://www.bwstudios.com/ScriptHelp.zip
Many thanks in advance.
Mark