Hotfolder action needed if possible!!!!

:|I am working - trying to set up a hotfolder that will run the following…

I am using distiller and i am wanting to create a script to run on the folder where the pdf’s are dropped into… the OUT folder…

The pdfs we are creating have a job number at the front of the name i.e 9500-test.PDF which relates to a job folder on our server…
I am wanting to create to folders within the job folder on the server 1. NEW and 2. OLD these folders will based on the server under the job number.

Then the next part is that when a PDF is placed in to the NEW folder thats fine but when we amended our artwork and create another PDF with the same file name the PDF drops in to the NEW folder again with the same name as before but this time i am wanting the old PDF to be moved in to the OLD folder and renamed with a different prefix at the end i.e 9500-test1.PDF so everytime we update the PDF and place into the NEW folder the old version automatically gets moved into the OLD folder as so we can keep a record of the amends and also all the PDF’s in the NEW folder are the latest and up to date…

I hope this is making sense and i am not sure if this is even possible.

any way here is the folder structure…

server------------server
active jobs-----folder
9500-------------folder
PDF---------------folder
NEW--------------folder
OLD--------------folder

i would really appreciate anybody who can sort out this mama out…

the other good thing would be able to put the script on the folder of the distiller ‘OUT’ folder and action it from there and not having to manually drop the file into the job folder NEW…

well i am sure this will give you guys something to chew on…

cheers

marc:D

Model: G5
AppleScript: 1.10.7
Browser: Safari 522.12
Operating System: Mac OS X (10.5)

Leaving aside the names and physical locations of your folders for the moment, you have a New folder and an Old folder and want a folder action for one of them. There are some details in the way, however – you can’t change the name of file in a folder with a folder action or the action triggers again. Files have to be moved first and renamed after that, first checking that a file with the same name is not already in the target and if there is, adding a suffix to the base name (before the extension) of the file.

I don’t think you can add a second file with the same name as one already in the folder without triggering a Finder response asking if you want to replace the one already there, so you need a third folder, the drop folder with an action, or you need a script application configured as a droplet. This script would check New for a duplicate name to the one dropped and if found rename and move the found file, first checking whether a number suffix was needed in Old, and then move the new file to New.

Have I understood?

Hi Adam

I think we have spoken before on this topic.
That seems how it might work as i agree if might not be possible to move then rename the file.
This would offer me the solution as the “NEW” folder will always contain the most up-to date PDF… and the “OLD” folder the history of the job sort of speak…

Is this a quick script set up as i am new to scripting???

would really appreciate you thoughts on this solution…

kind regards

marc

1 step closer to making my life much easier:cool:

Hi Marc,
rather than using a folder action I thought it might work better as a Stay Open application that just polled your Distiller out folder.
Please try saving the script below as a Stay open application and give it a go:

global out_folder
property active_jobs_folder : "Macintosh HD:active jobs:" as alias --> Put the path to your active jobs folder on your server here

set out_folder to choose folder --> You can hard code this part if you choose

on idle
	tell application "Finder"
		set pdf_list to every item of out_folder whose name ends with ".pdf"
		repeat with this_pdf in pdf_list
			set filename to name of this_pdf
			set folder_name to text 1 thru 4 of filename --> I've assumed the job number will always be 4 characters
			
			set job_folder to (active_jobs_folder as string) & folder_name & ":"
			set new_folder to (job_folder as string) & "New"
			set old_folder to (job_folder as string) & "Old"
			if not (exists folder job_folder) then --> If we cant find a Job folder that matches the job number then make one
				make new folder at active_jobs_folder with properties {name:folder_name}
			end if
			if not (exists folder new_folder) then --> If the job folder doesn't contain a New folder then make one
				make new folder at job_folder with properties {name:"New"}
			end if
			if not (exists folder old_folder) then --> If the job folder doesn't contain a Old folder then make one
				make new folder at job_folder with properties {name:"Old"}
			end if
			set job_folder to job_folder as alias
			set new_folder to new_folder as alias
			set old_folder to old_folder as alias
			
			set search_item to (new_folder as string) & filename
			if (exists file search_item) then
				--display dialog filename & " already exists in this location"
				my rename_old_pdf(search_item, old_folder, filename, new_folder, this_pdf)
			else
				move (this_pdf as alias) to new_folder
			end if
		end repeat
	end tell
end idle

on rename_old_pdf(search_item, old_folder, filename, new_folder, this_pdf)
	tell application "Finder"
		set number_flag to 1
		set file_exists to true
		repeat until file_exists is false
			set newname to text 1 thru -5 of filename & number_flag & ".pdf" as string
			set new_search_item to (old_folder as string) & newname
			if (exists file new_search_item) then
				set number_flag to number_flag + 1
				set file_exists to true
			else
				set the name of ((new_folder as string) & filename as alias) to newname
				move ((new_folder as string) & newname as alias) to old_folder
				move (this_pdf as alias) to new_folder
				--delete (this_pdf as alias) --> You may want to use this line to tidy up the out folder after this_pdf has been copied to your server
				set file_exists to false
			end if
		end repeat
	end tell
end rename_old_pdf

I’ve had to assume a few details so if I’ve got the wrong idea then please let me know.
Thanks,
Nik