hey,
ill admit i don’t really know what im doing, but here’s what im trying to do:
we’re a screenprint company who works in illustrator. the illustrator file is named by the design number, but when we send out pdfs for proofing to the client, we save the pdf as the ORDER number, which is in a text box within the file.
i worked out an automator action that compresses the .ai file into a .pdf, and parses out all the text into a separate file of the same name, and puts both files (pdf and txt) on the desktop. for some reason automator names these things crazy characters like “0skeh42s.pdf”, but the accompanying text file is the same name so they’re easy to match up.
what i’d like to do now is create an applescript that i could either drop these files on, or put inside the automator action (but i’ve just about given up on that part) that will:
-reference the pdf to the txt file
-open the txt file and look for the first 6 digit number between say 150000 and 300000 that doesn’t have any letters attached
-rename the pdf with this number
-delete the text file
so far i’ve gotten this one to work:
on open dropThese
repeat with oneFile in dropThese
set thePath to (oneFile) as text
set tName to name of (info for oneFile)
if tName does not contain ".txt" then
set txtPath to ((text 1 thru -4 of thePath) & "txt")
tell application "TextEdit"
open file (txtPath)
set orderText to (every paragraph in text of document 1 where it begins with "20") as text
if orderText is "" then
set orderText to (every paragraph in text of document 1 where it begins with "19") as text
end if
close document 1
end tell
set orderName to (text 1 thru 6 of orderText)
tell application "Finder"
set the name of oneFile to (orderName & ".pdf")
move txtPath to the trash
end tell
else
tell application "Preview"
open oneFile
end tell
end if
end repeat
end open
but as you can see it’s too restrictive. also, it picks up things like “20%”
this one makes more logical sense, but just hangs the system:
on open dropThese
repeat with oneFile in dropThese
set thePath to (oneFile) as text
set tName to name of (info for oneFile)
if tName does not contain ".txt" then
set txtPath to ((text 1 thru -4 of thePath) & "txt")
tell application "TextEdit"
open file (txtPath)
set theLine to 1
set orderText1 to 1
repeat
if orderText1 < 150000 then
try
set orderText1 to (text 1 thru 6 of paragraph theLine of document 1)
on error
set theLine to (theLine + 1)
end try
end if
end repeat
set orderText to orderText1 as text
close document 1
end tell
set orderName to (text 1 thru 6 of orderText)
tell application "Finder"
set the name of oneFile to (orderName & ".pdf")
move txtPath to the trash
end tell
else
tell application "Preview"
open oneFile
end tell
end if
end repeat
end open
finally, if this wasnt long enough, here’s a few examples of the text docs i’d be sifting through:
Thumbnail Size
200944
AW 7.28.09
Screen Print
WHITE
WILFLEX
WHITE
WILFLEX
Brite Org
WILFLEX
Black
WILFLEX
110 BK
110 OR
100%
#SP12971
#SP12971-1 (CU)Hit Somebody Rosman NC
(CU)Hit Somebody Rosman NC FB FB2
LC2 4 in x 3.75 in
12 in x 11 in 50% 35%
1.
1.
2.
Embroidery
FONT(S)
Thumbnail Size
50%
200486
TS 7.23.09
CUS PO: 714
#4624
File Name 4624 grand superior
pupcat
RES09R2_[AP]_F.Type FF+Apq.
C
315 x 129mm 12.4" x 5"
836 CC
836 CC
1090
emerald
1057
dk spice 1128
taupe
1002
white
1002
white
1109
fuschia
______%
Grk Pink
P. Twill
MarlinTeal
P. Twill
BRONZE
P TWILL TAN
P TWILL
White
P. Twill
White
P. Twill
split order evenly b/w colorways
1.
tackle
twill
2.
tackle
twill
3.
tackle
twill
A.
B.
C.
sorry for the long post, but i pasted the text so you can see that sometimes the order number appears in different places, and there may be all sorts of other numbers in the doc, but it will always be
6 characters,
between 150000 and 300000,
on its own line,
and be the the first of its kind in the txt (a reorder .ai file may have a text box with older order numbers, but those always appear further down in these text files)…
is the best way i can think to narrow it down.
any help would be much appreciated. thanks guys!