Copy new files in folder to another folder on another server.

I’m betting the problem is going to be that QLMH is not a constant, but just represents the files he has handy. I would bet that the file convetion is a 4 character client code followed by a 4 digit job code… together making a job ID.

Thanks guys. Things just got pretty busy here at work but I’ll be sure to review your posts today and tomorrow. I really appreciate the help. I’m still waiting for my AppleScript books so I’m a bit limited with my knowledge on this but I’m getting there.

Josh

Me too, myndcraft - that’s why I stuck on the adder. If his files are mixed, then something like this:


set clientCodes to {"QLMH", "AVDW", "VAGA", "QNCO"}
set someFiles to {"4013_QLMH0110.pdf", "QLMH0110AA.pdf", "QNCO0110BA_CO_BW_M.pdf", "QLMH0130F.pdf", "092_VAGA0128.pdf", "AVDW0120B.pdf", "someGarbageFile.pdf"} -- the garbage is skipped.

set shortNames to {} -- for demo purposes - something to do with the found result
repeat with aFile in someFiles
	repeat with aCode in clientCodes
		if contents of aCode is in contents of aFile then
			set end of shortNames to getShortName(contents of aCode, contents of aFile)
			exit repeat
		end if
	end repeat
end repeat

shortNames --> {"QLMH0110", "QLMH0110", "QNCO0110", "QLMH0130", "VAGA0128", "AVDW0120"}

to getShortName(code, fileName)
	set delim to code
	set d to AppleScript's text item delimiters -- save previous values
	set AppleScript's text item delimiters to delim
	set temp to text item 2 of fileName
	set AppleScript's text item delimiters to d -- set them back to what they were coming in
	return (delim & text 1 thru 4 of temp)
end getShortName

Yes, you are right, the QLMH part of the filename will change for other clients. My plan was to have a script/folder action for each client but it sounds like we may be able to consolidate into one script.

Some other filenames are:

CMGC0005.pdf
BSR0037A_backdrop_M.pdf
BUD0002_DealerBroch_M.pdf
BUD0012C_Poster_M.pdf
DZOO0075-HyenaLamarOutdoorM.pdf
632_JMUR0420.pdf
MWH0004C_QPEnvelope_M.pdf

Ultimately, I hope to achieve the following beyond this automated copying to subfolders. I thought I’d throw this out there to show you what my total plan is. I will be more able to take this on once I get my books within the next few days…

I hope to achieve the following:

Drag multiple Indesign files on script…
All files open in InDesign.
Within each file…
select all
ungroup all groupings
convert to outlines
export PDF to folder A with appropriate PDF preset
close InDesign file without saving
print PDF in folder A to laser printer (with print preset)
copy PDF from folder A to appropriate PDF Library subfolder (folder B) (this is the portion we are working on now)

Thanks guys!

Note that I’ve made some editing changes to my last script, so if you’ve copied it along the way (I forgot to check whether you were online) then get a fresh copy.

What does this mean: “print PDF in folder A to laser printer (with print preset)”? What’s a print preset?

I don’t have InDesign, so others will have to help up higher in your list.

EDIT: This works with your new file names, too.


set clientCodes to {"CMGC", "BSR", "BUD", "DZOO", "JMUR", "MWH"}
set someFiles to {"CMGC0005.pdf", "BSR0037A_backdrop_M.pdf", "someGarbageFile.pdf", "BUD0002_DealerBroch_M.pdf", "BUD0012C_Poster_M.pdf", "DZOO0075-HyenaLamarOutdoorM.pdf", "632_JMUR0420.pdf", "MWH0004C_QPEnvelope_M.pdf"} -- the garbage is skipped.

set shortNames to {} -- for demo purposes - something to do with the found result
repeat with aFile in someFiles
	repeat with aCode in clientCodes
		if contents of aCode is in contents of aFile then
			set end of shortNames to getShortName(contents of aCode, contents of aFile)
			-- Instead of setting Shortnames, of course, we'd be naming folders and duplicating files here.
			exit repeat
		end if
	end repeat
end repeat

shortNames --> {"CMGC0005", "BSR0037", "BUD0002", "BUD0012", "DZOO0075", "JMUR0420", "MWH0004", }

to getShortName(code, fileName)
	set delim to code
	set d to AppleScript's text item delimiters -- save previous values
	set AppleScript's text item delimiters to delim
	set temp to text item 2 of fileName
	set AppleScript's text item delimiters to d -- set them back to what they were coming in
	return (delim & text 1 thru 4 of temp)
end getShortName

Somewhere along the lines you need to come up with a constant… so you have to assume no matter what a few givens…

For this example I assumed the following…

1: The Client Code is 3-4 alphabetic characters in length
2: The Job Code is 4 numeric characters in length
3: The Client Code and Job Code are joined with no spaces or characters
4: The pattern of xxx[x]#### does not occur more than once in a given filename

With those assumptions in place it doesn’t matter what else is scattered within the file name allowing for a semi lazy approach to file naming by your creatives.

note This script requires the Satimage osax scripting addition found here.

This script takes a list of folder names, though you would process this one at a time in your on add handler not in a repeat loop, and extracts the matched pattern, your job ID, as outlined above and sets it to a variable. Again in this case to a list since we are processing a batch of file names and not a single name as we recieve it.

set someFiles to {"QBGH012.pdf", "QB1234.pdf", "4013_QLMH0110.pdf", "QLMH0110AA.pdf", "QNCO0110BA_CO_BW_M.pdf", "QLMH0130F.pdf", "092_VAGA0128.pdf", "AVDW0120B.pdf"}
set folderNames to {}
set regExExp to "\\w{3,4}[0-9]{4}"
repeat with aFile in someFiles
	try
		set end of folderNames to ({matchResult} of (find text regExExp in aFile with regexp)) as string
	end try
end repeat

-- Returns "QLMH0110", "QLMH0110", "QNCO0110", "QLMH0130", "VAGA0128", "AVDW0120"

I haven’t done much InDesign Scripting, but it shouldn’t be too difficult to do those steps from what I know. Check out the Dictionary, btw you do use Script Debugger right? I’ll also see if I can scrounge something up on my dev box tomorrow.

The Adobe apps allow you to, I believe, set prefence sets… so for Printing it could be do I print crop marks, bleeds, spreads, fit to page, etc…

You guys are amazing. I can’t believe the lengths that you are going to to help me. Thanks.

You are correct, myndcraft… Print Presets are just what you described. This preset also includes the specific printer that you are printing to.

I haven’t used the Script Debugger yet but I will.

Honestly, a bunch of this stuff that you have described is beyond me but I’ll get there quickly. My books will arrive in a day or two. For now, I’m going to test your most recent replies/scripts and will certainly get back to you.

Thanks again.

Hey jjdewiitt,

I’m sure I speak for everyone when I say glad we can help.

As for Script Debugger… While not a nessecity it’s my opinion that if your going to do any serious amount of scripting don’t leave home without it.

Now back to the issuse at hand… If there is anything specific we’ve shown so far that’s not quite clicking let us know and perhaps we can better explain it. As for the workflow though…

I think your steps may be out of order a tad bit though… If your using InDesign’s printer presets your going to have to keep it open to run the print out. I haven’t had a chance to actually test what you want to accomplish in InDesign, but I do know it’s all possible. A quick look at the dictionary for instance shows the print command for InDesign…

PRINT
print (verb): Print the object (from Standard Suite)

Command Syntax
print reference ¬
print dialog boolean ¬
using anything

Where anything is your Printer Preset to be used.

Hi guys,

Sorry for the delayed response. To clarify, I’ll need this script to including printing the pdf file as opposed to the InDesign file. Exploring your most recent replies now.

Thanks again.

Josh

Hmm, any particular reason why? I’m looking through Acrobat’s and AppleScript’s dictionary and I don’t see a option to specify a preset when printing though I do within InDesign’s dictionary.

Hi James,

I work at an ad agency… our ads are built in InDesign and we export pdfs from InDesign (after converting to outlines) that are sent to various publications for placement in newspapers, magazines, etc. Our procedures require that we have a hard copy print that represents the information (pdf file) that is sent to each publication. So, we need to print from the pdf file, not the InDesign file. After this pdf file is made and printed to our laser printer, we also copy this final pdf file to our pdf library.

Josh

So, I’m having trouble integrating the most recent recommendations to my existing script. My current script is as follows but, again, it is limited by the set folname to text 6 through 13 of (name of (info for thisFile)) line.

I am trying to understand and implement this script…

set clientCodes to {“CMGC”, “BSR”, “BUD”, “DZOO”, “JMUR”, “MWH”}
set someFiles to {“CMGC0005.pdf”, “BSR0037A_backdrop_M.pdf”, “someGarbageFile.pdf”, “BUD0002_DealerBroch_M.pdf”, “BUD0012C_Poster_M.pdf”, “DZOO0075-HyenaLamarOutdoorM.pdf”, “632_JMUR0420.pdf”, “MWH0004C_QPEnvelope_M.pdf”} – the garbage is skipped.

set shortNames to {} – for demo purposes - something to do with the found result
repeat with aFile in someFiles
repeat with aCode in clientCodes
if contents of aCode is in contents of aFile then
set end of shortNames to getShortName(contents of aCode, contents of aFile)
– Instead of setting Shortnames, of course, we’d be naming folders and duplicating files here.
exit repeat
end if
end repeat
end repeat

shortNames → {“CMGC0005”, “BSR0037”, “BUD0002”, “BUD0012”, “DZOO0075”, “JMUR0420”, “MWH0004”, }

to getShortName(code, fileName)
set delim to code
set d to AppleScript’s text item delimiters – save previous values
set AppleScript’s text item delimiters to delim
set temp to text item 2 of fileName
set AppleScript’s text item delimiters to d – set them back to what they were coming in
return (delim & text 1 thru 4 of temp)
end getShortName

My books should arrive any day so I should be more independent shortly…
http://www.spiderworks.com/books/automator.php
http://www.spiderworks.com/books/ashandbook.php

Thanks.

Josh

We are we getting hung up here?

BTW, your workflow sounds a lot like ours… the only difference being we print out mockups from InDesign not the PDF docs, though that is what we send out the door… PDF/X-1a:2001

I’m looking through Acrobat’s Library and, sadly, I’m not seeing a way to specify a preset when issuing a print command… I assume your printing would be done out of Acrobat. Perhaps it could be GUI scripted, but I’m not very familiar with it… perhaps some one could shed some insight?

Maybe there is an alternative way to print these pdfs within OS X without opening them in Acrobat?

Hi Josh, I wrote this as an illustration, but confess that I’ve now lost track of what your script looks like. Will you post what you’re currently working with again (in applescript tags - use the button to get them) and I’ll replace your folname to text 6 through 13 of (name of (info for thisFile)) line line with this much more flexible method of doing things.

PS: I’ll be out for a while, so it may not happen until tomorrow.

Adam

::cough::

set regExExp to "\\w{3,4}[0-9]{4}"
repeat with aFile in someFiles
	try
		set folderName to ({matchResult} of (find text regExExp in aFile with regexp)) as string
	end try
end repeat

::shortercodecough::

Okay so sure it needs a Scripting Addition, but its a good one :smiley:

Thanks.

This is where I am at now:

on adding folder items to thisFolder after receiving theFiles
	try
		tell application "Finder" to repeat with thisFile in theFiles
			set folname to text 6 through 13 of (name of (info for thisFile))
			duplicate file thisFile to folder ("PDF:QLM:QLMH_Library:" & folname) with replacing
		end repeat
	on error tError
		display dialog tError
	end try
end adding folder items to

With the new expanded capabilities of this script (to come), I’ll have to rework the current destination path that currently reads PDF:QLM:QLMH_Library:

The PDF: refers to our main PDF library…
Two example paths within this folder are:

PDF>QLM>QLMH_Library>QLMH0110 (this is the example we have been working with)

PDF>XcelEnergy>XCEL057

We probably could make these subfolders consistent by using the client code XCEL instead of XcelEnergy but you hopefully get the idea. The QLMH0110 and XCEL057 are specific job numbers where files for that job are to be copied to. There are other folders at that same “level” with different job numbers but the same letter code. For example, XCEL089, XCEL050 are also in the XcelEnergy folder and QLMH0128, QLMH0230 are also in the QLMH_Library.

So how about something like this…

on adding folder items to thisFolder after receiving theFiles
	try
		tell application "Finder" to repeat with thisFile in theFiles
			set folname to do shell script "perl -e '$_ = \"" & thisFile & "\";m/(\\w{3,4}[0-9]{4})/;print $1'"
			set cCode to text 1 through -5 of folname as string
			duplicate file thisFile to folder ("PDF:" & cCode & ":" & cCode & "_Library:" & folname) with replacing
		end repeat
	on error tError
		display dialog tError
	end try
end adding folder items to

So for a given set of files say {“QLMH0110.pdf”, “XCEL0145.pdf”, “BSR0037A_backdrop_M.pdf”} you would end up with the following file paths

PDF>QLMH>QLMH_Library>QLMH0110
PDF>XCEL>XCEL_Library>XCEL0145
PDF>BSR>BSR_Library>BSR0037

And look I did one without requiring a scripting addition LOL

Always the best way when dealing with scripts someone else has to get going (excluding StandardAdditions, of course) :wink: