Two weeks ago I started attempting to learn applescript as a way to make things simpler in my department. After much reading of these forums, lots of trial and error, and enough expletives to hurt someone I have a script that will extract individual pages from multi-page PDF files and rename them sequentially for imposition.
There are several things in the script that, I feel, are less efficient than they could be, but my extreme noobescence(?) has its limits. (I don’t know what I’m doing or talking about, but this script is long and clunky and requires too many mouse clicks for my taste.) Please, look it over and let me know what changes I could make to optimize this nasty, little jewel.
Thank you for your time and input.
Pat (omitted)
tell application "Finder"
--This bothers me because it assumes that there is an alias called "Acrobatlaunch" on disk "Samson"
--Is there a way that I could make it work on any machine with Acrobat 7 running OSX?
open file "Samson:Applications:Acrobatlaunch"
end tell
--BEGIN REPEATED BLOCK
tell application "Adobe Acrobat 7.0 Professional"
activate
choose file with prompt "Select PDF to Covert to Single Page"
copy the result to Orgdoc
open Orgdoc
end tell
tell application "Finder"
activate
set Orgdocname to name of Orgdoc as string
end tell
tell application "Adobe Acrobat 7.0 Professional"
activate
set PageCount to ""
set Orgdoc to the front document
set PageCount to page count
tell application "System Events"
tell process "Acrobat"
click menu item "Number Pages..." of menu "Advanced" of menu bar item "Advanced" of menu bar 1
delay 1
tell group 1 of group 2 of group 1 of window "Page Numbering"
click radio button "All"
end tell
delay 0.5
tell group 1 of window "Page Numbering"
click button 1
end tell
end tell
end tell
delay 0.5
tell application "System Events"
tell process "Acrobat"
click menu item "Extract Pages..." of menu "Document" of menu bar item "Document" of menu bar 1
delay 1
keystroke tab
keystroke (PageCount as string)
delay 0.5
click checkbox "Extract Pages As Separate Files" of group 1 of window "Extract Pages"
click button "OK" of group 1 of window "Extract Pages"
end tell
set goahead to display dialog "Select Destination for output and Press OK once document is finished extracting." buttons {"OK", "Not OK"} default button 1
set goahead2 to button returned of goahead
if goahead2 is "OK" then
close Orgdoc saving no
end if
end tell
end tell
tell me
activate
end tell
set temp to display dialog "Would you like to process another PDF?" buttons {"No", "Yes"} default button 2
set pressed to button returned of temp
--END REPEATED BLOCK
repeat until pressed is not "Yes"
tell application "Adobe Acrobat 7.0 Professional"
activate
choose file with prompt "Select PDF to Covert to Single Page"
copy the result to Orgdoc
open Orgdoc
end tell
tell application "Finder"
activate
set Orgdocname to name of Orgdoc as string
end tell
tell application "Adobe Acrobat 7.0 Professional"
activate
set PageCount to ""
set Orgdoc to the front document
set PageCount to page count
tell application "System Events"
tell process "Acrobat"
click menu item "Number Pages..." of menu "Advanced" of menu bar item "Advanced" of menu bar 1
delay 1
tell group 1 of group 2 of group 1 of window "Page Numbering"
click radio button "All"
end tell
delay 0.5
tell group 1 of window "Page Numbering"
click button 1
end tell
end tell
end tell
delay 0.5
tell application "System Events"
tell process "Acrobat"
click menu item "Extract Pages..." of menu "Document" of menu bar item "Document" of menu bar 1
delay 1
keystroke tab
keystroke (PageCount as string)
delay 0.5
click checkbox "Extract Pages As Separate Files" of group 1 of window "Extract Pages"
click button "OK" of group 1 of window "Extract Pages"
end tell
set goahead to display dialog "Select Destination for output and Press OK once document is finished extracting." buttons {"OK", "Not OK"} default button 1
set goahead2 to button returned of goahead
if goahead2 is "OK" then
close Orgdoc saving no
end if
end tell
end tell
tell me
activate
end tell
set temp to display dialog "Would you like to process another PDF?" buttons {"No", "Yes"} default button 2
set pressed to button returned of temp
end repeat
set rename to display dialog "Would you like to sequentially rename files?" buttons {"OK", "Not OK"} default button 1
set rename2 to button returned of rename
if rename2 is "OK" then
tell application "Finder"
--choose folder
choose folder with prompt "Select Folder for sequential content renaming"
copy the result to Orgfold
--How could I add a leading zero to files numbered less than 10?
-- get the current folder listing
set sourceFiles to every file of Orgfold
-- start off with file 1
set fileCounter to 1
--loop through the files
repeat with aFile in sourceFiles
--renaming each one in turn
set name of aFile to fileCounter as string
-- and incrementing the counter after each file
set fileCounter to fileCounter + 1
end repeat
end tell
end if