Heres the idea behind the script. Folder Action. PDF files are placed in folder. PDF file is opened in Acrobat, image is copied and then closed. PDF file (art template) is opened in Acrobat, information form original PDF is pasted in and then closed. I’ve got all that. Where I’m getting stuck is this last part. Newly created PDF file is given the same name as the original file that had information cut from with the current date appended. Newly created PDF goes into new folder (partly done).
OK, I have clodged together the following using the Folderaction scripts that came on the machine and making my own edits. Probably there is some errorchecking stuff in there that doesn’t need to be in there. Hopefully somebody can show me how to set up this naming… Thanks all!
property done_foldername : "Customer PDF"
property type_list : {"PDF"}
property extension_list : {"pdf"}
on adding folder items to this_folder after receiving these_items
tell application "Finder"
set the target_folder to alias "Ren Mark G4-5:tester:"
end tell
-- PROCESS EACH OF THE ITEMS ADDED TO THE ATTACHED FOLDER
try
repeat with i from 1 to number of items in these_items
set this_item to item i of these_items
set the item_info to the info for this_item
-- CHECK TO SEE IF THE ITEM IS AN IMAGE FILE OF THE ACCEPTED FILE TYPE
if (alias of the item_info is false and the file type of the item_info is in the type_list) or (the name extension of the item_info is in the extension_list) then
tell application "Finder"
-- LOOK FOR EXISTING MATCHING ITEMS IN THE DESTINATION FOLDER
-- IF THERE ARE MATCHES, THEN RENAME THE CONFLICTING FILES INCREMENTALLY
my resolve_conflicts(this_item, target_folder)
-- MOVE THE ITEM TO THE DESTINATION FOLDER
set the target_file to (move this_item to the target_folder with replacing) as alias
end tell
-- PROCESS THE ITEM
process_item(target_file)
end if
end repeat
on error error_message number error_number
if the error_number is not -128 then
tell application "Finder"
activate
display dialog error_message buttons {"Cancel"} default button 1 giving up after 120
end tell
end if
end try
end adding folder items to
on resolve_conflicts(this_item, target_folder)
tell application "Finder"
set the file_name to the name of this_item
if (exists document file file_name of target_folder) then
set file_extension to the name extension of this_item
if the file_extension is "" then
set the trimmed_name to the file_name
else
set the trimmed_name to text 1 thru -((length of file_extension) + 2) of the file_name
end if
set the name_increment to 1
repeat
set the new_name to (the trimmed_name & "." & (name_increment as string) & "." & file_extension) as string
if not (exists document file new_name of the target_folder) then
-- rename to conflicting file
set the name of document file file_name of the target_folder to the new_name
exit repeat
else
set the name_increment to the name_increment + 1
end if
end repeat
end if
end tell
end resolve_conflicts
-- this sub-routine processes files
on process_item(this_item)
-- NOTE that the variable this_item is a file reference in alias format
-- FILE PROCESSING STATEMENTS GOES HERE
try
-- convert alias reference to string
set this_item to this_item as string
with timeout of 900 seconds
tell application "Adobe Acrobat 7.0 Pro#DE835"
launch -- always use with Folder Actions
set this_image to open file this_item
end tell
tell application "Adobe Acrobat 7.0 Pro#DE835"
activate
end tell
tell application "System Events"
launch
keystroke "a" using command down
keystroke "x" using command down
end tell
delay 4
tell application "Adobe Acrobat 7.0 Pro#DE835"
close all docs saving no
end tell
tell application "Adobe Acrobat 7.0 Pro#DE835"
open alias "Ren Mark G4-5:Documents:Proof Template.pdf"
activate
end tell
tell application "System Events"
launch
keystroke "v" using command down
end tell
delay 4
tell application "Adobe Acrobat 7.0 Pro#DE835"
save document 1 to target_folder
close all docs saving no
end tell
end timeout
on error error_message
tell application "Finder"
activate
display dialog error_message buttons {"Cancel"} default button 1 giving up after 120
end tell
end try
end process_item