I am trying to set up a script that will add a bookmark to each PDF file in given folder which will allow the user to return to the previous document.
AppleScript returns an error that reads: System Events got an error: Can’t get window “Bookmark Properties” of process “Acrobat”.
It stalls just after the “keystroke ‘i’ using {command down}” line.
I have tried adding statements like “get window …” or “select window …” but that doesn’t seem to help.
I got my GUI commands from the UI Browser by PreFab software.
Any help you may have would be appreciated.
Thanks, Jennie
set batchFolder to (choose folder with prompt "Choose PDF directory")
tell application "Finder" to set listOfFiles to (get every file of folder batchFolder) as list
--creates list of files from chosen directory
activate application "Adobe Acrobat Professional"
repeat with imageFile in listOfFiles
tell application "Finder" to open imageFile
activate application "Adobe Acrobat Professional"
tell application "System Events"
tell process "Acrobat"
click menu item "Bookmarks" of menu 1 of menu item "Navigation Panels" of menu 1 of menu bar item "View" of menu bar 1
click menu item "Add Bookmark" of menu 1 of menu bar item "Document" of menu bar 1
keystroke "return to previous document"
keystroke return -- return key
keystroke "i" using {command down}
click radio button "Actions" of tab group 1 of window "Bookmark Properties"
click button "Delete" of group 2 of tab group 1 of window "Bookmark Properties"
click button "Add..." of group 1 of tab group 1 of window "Bookmark Properties"
select static text "View>Go To>Previous View" of row 21 of outline 1 of scroll area 1 of window "Menu Item"
keystroke return -- return key
keystroke tab -- forward tab key
keystroke tab -- forward tab key
keystroke tab -- forward tab key
keystroke tab -- forward tab key
keystroke tab -- forward tab key
keystroke return -- return key
click menu item "Save" of menu 1 of menu bar item "File" of menu bar 1
end tell
end tell
end repeat
Model: iMac G5
AppleScript: 2.0
Browser: Safari 523.10.6
Operating System: Mac OS X (10.5)
UI scripting is often critical in terms of time.
I recommend to check the existence of a window every time it’s going to open
.
keystroke "i" using {command down}
repeat until exists window "Bookmark Properties"
delay 0.5
end repeat
tell tab group 1 of window "Bookmark Properties"
click radio button "Actions"
click button "Delete" of group 2
click button "Add..." of group 1
end tell
repeat until exists window "Menu Item"
delay 0.5
end repeat
select static text "View>Go To>Previous View" of row 21 of outline 1 of scroll area 1 of window "Menu Item"
.
I was able to solve the problem with the script by adding delays… also, see Stefan’s post where he groups some items. That would be helpful as well.
Here is my completed script as I have it running properly now.
–Jennie
set batchFolder to (choose folder with prompt "Choose PDF directory")
tell application "Finder" to set listOfFiles to (get every file of folder batchFolder) as list
--creates list of files from chosen directory
activate application "Adobe Acrobat Professional"
repeat with imageFile in listOfFiles
tell application "Finder" to open imageFile
activate application "Adobe Acrobat Professional"
tell application "System Events"
tell process "Acrobat"
click menu item "Bookmarks" of menu 1 of menu item "Navigation Panels" of menu 1 of menu bar item "View" of menu bar 1
delay 1
click menu item "Add Bookmark" of menu 1 of menu bar item "Document" of menu bar 1
delay 1
keystroke "return to previous document" -- adds text to bookmark
keystroke return -- return key
keystroke "i" using {command down}
delay 1
click radio button "Actions" of tab group 1 of window "Bookmark Properties"
delay 1
click button "Delete" of group 2 of tab group 1 of window "Bookmark Properties"
delay 1
click button "Add..." of group 1 of tab group 1 of window "Bookmark Properties"
delay 1
keystroke (ASCII character 31) -- down arrow key
keystroke (ASCII character 31) -- down arrow key
keystroke (ASCII character 31) -- down arrow key
keystroke (ASCII character 31) -- down arrow key
keystroke (ASCII character 31) -- down arrow key
keystroke (ASCII character 31) -- down arrow key
keystroke (ASCII character 31) -- down arrow key
keystroke (ASCII character 31) -- down arrow key
keystroke (ASCII character 31) -- down arrow key
keystroke (ASCII character 31) -- down arrow key
keystroke (ASCII character 31) -- down arrow key
keystroke (ASCII character 31) -- down arrow key
keystroke (ASCII character 31) -- down arrow key
keystroke (ASCII character 31) -- down arrow key
keystroke (ASCII character 31) -- down arrow key
keystroke (ASCII character 31) -- down arrow key
keystroke (ASCII character 31) -- down arrow key
keystroke (ASCII character 31) -- down arrow key
keystroke (ASCII character 31) -- down arrow key
keystroke return -- return key
keystroke tab -- forward tab key
keystroke tab -- forward tab key
keystroke tab -- forward tab key
keystroke tab -- forward tab key
keystroke tab -- forward tab key
keystroke return -- return key
click menu item "Save" of menu 1 of menu bar item "File" of menu bar 1
click menu item "Close" of menu 1 of menu bar item "File" of menu bar 1
end tell
end tell
end repeat
Model: iMac G5
AppleScript: 2.0
Browser: Safari 523.10.6
Operating System: Mac OS X (10.5)
the delays and especially the bunch of keystroke lines to specify the list item are not needed
Here an optimized version
set batchFolder to (choose folder with prompt "Choose PDF directory")
tell application "Finder" to set listOfFiles to (get every file of folder batchFolder) as list
-- creates list of files from chosen directory
activate application "Adobe Acrobat Professional"
repeat with imageFile in listOfFiles
tell application "Adobe Acrobat Professional"
open (imageFile as alias)
tell document 1 to set view mode to pages and bookmarks
end tell
tell application "System Events"
tell process "Acrobat"
keystroke "b" using command down
delay 1
keystroke "return to previous document" -- adds text to bookmark
keystroke return
keystroke "i" using command down
repeat until exists window "Bookmark Properties"
delay 0.5
end repeat
tell tab group 1 of window "Bookmark Properties"
click radio button "Actions"
click button "Delete" of group 2
click button "Add..." of group 1
end tell
repeat until exists window "Menu Item"
delay 0.5
end repeat
tell outline 1 of scroll area of window "Menu Item"
set value of attribute "AXselected" of (1st row whose value of static text 1 is "View>Go To>Previous View") to true
end tell
click button "OK" of window "Menu Item"
click button "OK" of window "Bookmark Properties"
end tell
tell application "Adobe Acrobat Professional" to close document 1 saving yes
end tell
end repeat