I am trying to figure out how to write an applescript that would open a folder of PDF’s (once dropped on it), go to the file menu-“Reduce File Size” and save over themselves.
I can’t find anything in the dictionary on this…can any one help me…
…any help would be greatly appreciated…
thanks!!
barbara
I have gotten this far (but they don’t close…)
I am getting to the point where I can get it to open a pdf…
I think I need a system event to tell acrobat to go to the file menu and choose “reduce file size”, but I am not sure…
on open FileList
tell application “Adobe Acrobat 7.0 Professional”
activate
repeat with i in FileList
open i
–file menu-reduce file size-here us what I cannot figure out
save i (save over the same file)
close i
end repeat
end tell
end open
thanks…I wait for your thoughts…like I said, I think I got some parts to work…but I really need to use system events I think to reduce file size, as it is not in the dictionary…
Okay I got this to work… currently I did it by manually setting the file, but adapting this to be a folder action isn’t that difficult. The more annoying thing about this is though is determining the amount of time to set the delays too… In almost all instances the first few should be okay.
The hard one though is the delay before closing a document. The larger the file, generally, the longer it needs to reduce so you may have to play with this a bit to find a number that works across a range of situations.
Another idea might be to check file size and then use some logic to come up with a fitting delay time. Anyways here ya go:
set theFile to "HD:Users:username:Desktop:Test.pdf"
set fileName to name of (get info for file theFile)
activate application "Adobe Acrobat 7.0 Professional"
tell application "System Events"
tell process "Acrobat"
open theFile
delay 1
click menu item "Reduce File Size..." of menu 1 of menu bar item "File" of menu bar 1
delay 1
click button "OK" of group 1 of window "Reduce File Size"
delay 2
click button "Save" of window "Save As"
delay 1
click button "Replace" of window 1
delay 15
click button 4 of window fileName
end tell
end tell
uhhhhh…I was supposed to do something with the filename??? ohhhh
set theFile to “Macintosh HD:Users:training3:Desktop:Test.pdf”
set fileName to name of (get info for file theFile)
activate application “Adobe Acrobat 7.0 Professional”
tell application “System Events”
tell process “Acrobat”
open theFile
delay 1
click menu item “Reduce File Size…” of menu 1 of menu bar item “File” of menu bar 1
delay 1
click button “OK” of group 1 of window “Reduce File Size”
delay 2
click button “Save” of window “Save As”
delay 1
click button “Replace” of window 1
delay 15
click button 4 of window fileName
close document
end tell
end tell
Oh so you were using the same script I posted… I was checking to see if you had modified, but you had meant my original wasn’t working.
My guess is your window isn’t named the same as the file name as returned by info for. perhaps due to extensions being hidden /shrug
What is the name of the file you are trying as it appears in the title of the Acrobat window? When you run the script what value is fileName being assigned?
Also in the meantime though try this…
set theFile to "HD:Users:username:Desktop:Test.pdf"
activate application "Adobe Acrobat 7.0 Professional"
tell application "System Events"
tell process "Acrobat"
open theFile
delay 1
click menu item "Reduce File Size..." of menu 1 of menu bar item "File" of menu bar 1
delay 1
click button "OK" of group 1 of window "Reduce File Size"
delay 2
click button "Save" of window "Save As"
delay 1
click button "Replace" of window 1
delay 15
end tell
end tell
tell application "Adobe Acrobat 7.0 Professional" to close all docs saving "No"
hi,
Actually, I just changed it to point to my hard drive, my users folder, desktop and I made a file called test.pdf. That is why it worked up until the close…
I’m going to try and figure out how to get this script to open up a folder of PDF’s and get then to close… I’m gonna try… Don’t know how far I will get…
Going to work on it tonight… i will send you my results tomorrow…
Will you get the email alert then?
I just subscribed, so yes I will get the alert. In the meantime though I went and made a version that selects a folder (at run time) and processes all files within.
::Note:: I moved the open statement to combat a problem where Preview “preferred” pdfs were opening there as oppossed to Acrobat.
set theFolder to choose folder
tell application "Finder" to set theFiles to entire contents of theFolder
activate application "Adobe Acrobat 7.0 Professional"
repeat with aFile in theFiles
tell application "Adobe Acrobat 7.0 Professional" to open (aFile as string)
tell application "System Events"
tell process "Acrobat"
delay 1
click menu item "Reduce File Size..." of menu 1 of menu bar item "File" of menu bar 1
delay 1
click button "OK" of group 1 of window "Reduce File Size"
delay 2
click button "Save" of window "Save As"
delay 1
click button "Replace" of window 1
delay 15
end tell
end tell
tell application "Adobe Acrobat 7.0 Professional" to close all docs saving "No"
end repeat
You have a good night too! If you start doing more scripting that requires maipulating the GUI I recommend taking a look at PreFab UI Browser (http://prefabsoftware.com/uibrowser/) – I wouldn’t even think of trying GUI Scripting without it =)
Hi James,
I dowloaded that demo of the GUI element you told me about… Looks cool…
Again, I thank you for your help yesterday…reading your script on the bus made a lot of sense… I look forard to the day, I can write them on my own.
babs
Hi James,
Are you still out there? I have the applescript bug…started reading he missing manual this week and I try to write a little script everyday for practice… so far, they have been very simple…today, I tried something more complicated, and used your script from last week to guide me…
Instead of “Reduce File size” from the menu…I wanted to print a batch of images… I replaced all (the very few) necessary words, and thought it would work like a charm…But no. Doesn’t get past the first Print line… I have looked and looked, but it would seem right… if you get a moment, can you look at it and see if you can see what I did wrong ;-(
thanks!
set theFolder to choose folder
tell application “Finder” to set thefiles to entire contents of theFolder
repeat with aFile in thefiles
tell application “Adobe Acrobat 7.0 Professional” to open (aFile as string)
tell application “System Events”
tell process “Acrobat”
delay 2
click menu item “Print…” of menu 1 of menu bar item “File” of menu bar 1
delay 1
click button “Print” of group 1 of window “Print”
delay 2
click button “Save” of window “Save As”
delay 1
click button “Replace” of window 1
delay 5
end tell
end tell
tell application “Adobe Acrobat 7.0 Professional” to close all docs saving “No”
end repeat