PDA

View Full Version : How to get 2 scripts to work together? Illustrator & Acrobat Pro PDFs




brianedl
May 23, 2012, 04:30 PM
I just started looking into using Applescript.

I'm working on creating a folder that when I drop 1 or 300 Illustrator files into it the script will

1) Open the .ai file in Illustrator save as .pdf with same name. (I have a script that does this see Script #1 below)

2) Then opens the .pdf file in Acrobat Pro & converts pdf to "Enable Commenting & Measuring" keeping the same name (I have a script that does this see Script #2 below)

Note: I do not know how to combined them into one script so the script does this to each file one at a time.

3) Then when 1 & 2 are complete I would like the .ai file & converted .pdf file to be moved to a different folder based on the first 6 characters of its name.

Example:
If a file is named "ILDG93-180101-14401-AA01.ai" then because it starts with "ILDG93" it will know to move both files .ai & .pdf to a folder called "CD4.1"
but then
If a file is named "ILCJ54-180101-14401-AA01.ai" then because it starts with "ILCJ54" it will know to move both files .ai & .pdf to a folder called "C520" & so on...

4) Then moves on to the next .ai file until all are complete.


One more thing I was hoping that if 10 files were dropped into the folder & it was in the middle of processing the 10 .ai files & at that time more files were dropped into the folder it would be able to just keep working on the 10 & continue to the new files until all are done.

:D If anyone knows how to do any of this even if not all I'm asking I would be so THANKFUL!

Script #1 SAVE AS .ai as .pdf

-- fileList is a list of aliases to Illustrator files
-- destFolder is an alias to a folder where PDF files are saved
on SaveFilesAsPDF(fileList, destFolder)
set destPath to destFolder as Unicode text
repeat with aFile in fileList
tell application "Finder" to set fileName to name of aFile
set newFilePath to destPath & fileName
tell application "Adobe Illustrator"
open aFile
save current document in file newFilePath as pdf with options {class:PDF save options, acrobat layers:false, compatibility:Acrobat 8, preserve editability:false, font subset threshold:0.0}
close current document saving no
end tell
end repeat
end SaveFilesAsPDF
-- Call handler
set sourceFolder to "Macintosh HD:Users:b3po:Public:AI to PDF to Enabled"
tell application "Finder" to set fileList to every file of folder "Macintosh HD:Users:b3po:Public:AI to PDF to Enabled" as alias list
set destFolder to "Macintosh HD:Users:b3po:Public:PDF Enabler:"
SaveFilesAsPDF(fileList, destFolder)

--tell application "Finder" to set theFiles to every document file of folder "Macintosh HD:Users:b3po:Public:AI to PDF to Enabled" whose file type ends with "ai"


Script #2 CONVERT pdf "Enable Commenting & Measuring"

property documentList : {}

on open names
set documentList to {}
tell application "Finder"
repeat with i in names
set documentList to documentList & ((i as alias) as string)
end repeat
repeat with i in documentList -- in case multiple objects dropped on applet
if i ends with ":" then -- if object is a folder process its contents too
set newList to entire contents of (i as alias)
repeat with j in newList
set documentList to documentList & (j as string)
end repeat
end if
end repeat
end tell
my process_documents(documentList)
end open

on process_documents(theList)
repeat with aDocument in theList
if (aDocument does not end with ":") then
tell application "Adobe Reader"
set myDocument to open (alias aDocument)
end tell
tell application "System Events"
try
tell process "Acrobat"
-- bring acrobat to the front
set frontmost to true
set windowName to value of static text 1 of window 1
-- select the enable commenting menu item
try
-- Acrobat Pro 9
click menu item "Enable for Commenting and Analysis in Adobe Reader..." of menu 1 of menu bar item "Comments" of menu bar 1
on error
-- Acrobat Pro X
try
-- OS X Snow Leopard
click menu item "Enable Commenting & Measuring..." of menu 1 of menu item "Reader Extended PDF" of menu 1 of menu item "Save As..." of menu 1 of menu bar item "File" of menu bar 1
on error
-- OS X Lion
click menu item "Enable Commenting & Measuring..." of menu 1 of menu item "Reader Extended PDF" of menu 1 of menu item "Save As" of menu 1 of menu bar item "File" of menu bar 1
end try
end try

-- change save as filename
-- wait until save dialog is opened
set saveDialogActive to false
repeat until saveDialogActive is true
try
set fileName to value of text field 1 of window "Save As"
set saveDialogActive to true
on error
set saveDialogActive to false
end try
end repeat

set value of text field 1 of window "Save As" to fileName
-- save file
click button "Save" of window "Save As"
if exists sheet 1 of window "Save As" then
click button "Replace" of sheet 1 of window "Save As"
end if
end tell
end try
end tell

-- stop processing until window is closed
set windowActive to true
repeat until windowActive is false
tell application "System Events"
try
tell process "Acrobat"
-- bring acrobat to the front
set frontmost to true
-- close file
click button 1 of window windowName
set windowName to value of static text 1 of window 1
end tell
on error
set windowActive to false
end try
end tell
end repeat

end if
end repeat
end process_documents

on replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars


Model: imac
AppleScript: 2.3
Browser: Safari 534.55.3
Operating System: Mac OS X (10.6)



brianedl
Jun 5, 2012, 08:46 AM
divster was able to put these together.


This works on my Mac. I have Illustrator's preferences to open a PDF after saving, which you would have to do manually beforehand. All I did was take your second script handler, remove its repeat section and call the handler before Illustrator moved on to opening its next document.

Regarding your last point, I don't think you would be able to interrupt the script with some more work, Maybe some kind of watched folder thing would do it.

-- fileList is a list of aliases to Illustrator files
-- destFolder is an alias to a folder where PDF files are saved
on SaveFilesAsPDF(fileList, destFolder)
set destPath to destFolder as Unicode text
repeat with aFile in fileList
tell application "Finder" to set fileName to name of aFile
set newFilePath to destPath & fileName
tell application "Adobe Illustrator"
open aFile
save current document in file newFilePath as pdf with options {class:PDF save options, acrobat layers:false, compatibility:Acrobat 8, preserve editability:false, font subset threshold:0.0}
close current document saving no
end tell
my process_documents()
end repeat
end SaveFilesAsPDF
-- Call handler
set sourceFolder to "Macintosh HD:Users:Dave:Desktop:Illustrator:"
tell application "Finder" to set fileList to every file of folder sourceFolder -- "Macintosh HD:Users:b3po:Public:AI to PDF to Enabled" as alias list
set destFolder to "Macintosh HD:Users:Dave:Desktop:PDF:"
SaveFilesAsPDF(fileList, destFolder)

--tell application "Finder" to set theFiles to every document file of folder "Macintosh HD:Users:b3po:Public:AI to PDF to Enabled" whose file type ends with "ai"

on process_documents()
tell application "System Events"
try
tell process "Acrobat"
-- bring acrobat to the front
set frontmost to true
set windowName to value of static text 1 of window 1
-- select the enable commenting menu item
try
-- Acrobat Pro 9
click menu item "Enable for Commenting and Analysis in Adobe Reader..." of menu 1 of menu bar item "Comments" of menu bar 1
on error
-- Acrobat Pro X
try
-- OS X Snow Leopard
click menu item "Enable Commenting & Measuring..." of menu 1 of menu item "Reader Extended PDF" of menu 1 of menu item "Save As..." of menu 1 of menu bar item "File" of menu bar 1
on error
-- OS X Lion
click menu item "Enable Commenting & Measuring..." of menu 1 of menu item "Reader Extended PDF" of menu 1 of menu item "Save As" of menu 1 of menu bar item "File" of menu bar 1
end try
end try

-- change save as filename
-- wait until save dialog is opened
set saveDialogActive to false
repeat until saveDialogActive is true
try
set fileName to value of text field 1 of window "Save As"
set saveDialogActive to true
on error
set saveDialogActive to false
end try
end repeat

set value of text field 1 of window "Save As" to fileName
-- save file
click button "Save" of window "Save As"
if exists sheet 1 of window "Save As" then
click button "Replace" of sheet 1 of window "Save As"
end if
end tell
end try
end tell

-- stop processing until window is closed
set windowActive to true
repeat until windowActive is false
tell application "System Events"
try
tell process "Acrobat"
-- bring acrobat to the front
set frontmost to true
-- close file
click button 1 of window windowName
set windowName to value of static text 1 of window 1
end tell
on error
set windowActive to false
end try
end tell
end repeat
end process_documents

Model: MacBook Pro
AppleScript: 2.1.2
Browser: Safari 533.19.4
Operating System: Mac OS X (10.6)[COLOR="#808080"]

brianedl
Jun 5, 2012, 04:10 PM
I really tried! Over & Over again!
I have 2 options that move files base on the name but am not sure how to connect it all together? Do you have any idea?

OPTION 1:

A program called "HAZEL" cost $25 & my well be worth it.

The script right now (THANKS TO divster) opens each .ai file in Illustrator one at a time then "save as" a .pdf then opens the .pdf in Acrobat Pro to make "Enable Commenting & Measuring..."

If in the script we could add a simple move command to move the .ai file & .pdf file when finished to an "Other Folder" then I could with HAZEL have that "Other Folder" watched to push all the files to their correct final folder based on their name.

So it would:

one at a time open each .ai file in Illustrator then "save as" a .pdf then open the .pdf in Acrobat Pro to make "Enable Commenting & Measuring..." Then moves both completed files to an other folder & then repeats to the next .ai until all .ai's & .pdf's are processed & moved out to the next folder

Would it be easy to add this? I'm thinking not to hard, but what do I know. I am going to try to do it but am always scared to death when scripting, I always wonder if I forgot one little detail or am totally off.



OPTION 2:

This could work if I could get it to run the conversion script 1st then move both .ai & new .pdf one file at a time.

But maybe the HAZEL option is better because it can do more than just move files based on their name? Just a guess.

tell application "Finder"
set this_folder to folder "Macintosh HD:Users:brianlau:Desktop:Drop pdf's"
set this_list to every file of this_folder
repeat with i in this_list
if (name of i) begins with "ILCJ54" then
move i to "Macintosh HD:Users:brianlau:Desktop:Completed Pages:C520-13 CJ54:" with replacing

else if (name of i) begins with "ILDM51" then
move i to "Macintosh HD:Users:brianlau:Desktop:Completed Pages:C346-13 DM51:" with replacing

else if (name of i) begins with "ILDE83" then
move i to "Macintosh HD:Users:brianlau:Desktop:Completed Pages:B299-14 DE83:" with replacing

else if (name of i) begins with "ILEJ73" then
move i to "Macintosh HD:Users:brianlau:Desktop:Completed Pages:C489-14 EJ73:" with replacing

else if (name of i) begins with "ILFT43" then
move i to "Macintosh HD:Users:brianlau:Desktop:Completed Pages:CD4.2-15 FT43:" with replacing

end if
end repeat
end tell