Resaving PDFs with Enable for Commenting and Analysis

Hi,

I am new to applescript. I have one new task with me.

And the task is:
We have a bunch of PDFs, what we have to do is to resave each and every PDF with “Enable for Commenting and Analysis in Adobe Reader” turned on.

Can anyone help me to write the code in applescript.

Thanks,
Krishnan

Running Acrobat 8 Pro over here and this seems to do the trick. As this uses GUI scripting your mileage may vary :slight_smile:

set thePDFs to choose file with prompt "Select the PDF(s) to enable commenting on" with multiple selections allowed

repeat with aPDF in thePDFs
	tell application "Adobe Acrobat Professional"
		open aPDF
	end tell
	activate application "Adobe Acrobat Professional"
	tell application "System Events"
		tell process "Acrobat"
			click menu item "Enable for Commenting and Analysis in Adobe Reader..." of menu 1 of menu bar item "Comments" of menu bar 1
			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 tell
	tell application "Adobe Acrobat Professional"
		close every document
	end tell
end repeat

Thanks James,

When I run this script, I got the applescript error message:

System Events got an error:
NSReceiverEvaluationScriptError: 4

Kindly advice us how to correct this error.

Thanks,
Krishnan

Hi,

Enable access for assistive devices in System Preferences > Universal Access

doh!

Thanks Stefan =)

Thanks Stefan for your answer.

Gopal

I need to accomplish the same thing. I get the same error mentioned above. I have the Enable Access for… checked. Is there something else causing this error?

Thanks
James

I just updated my script for OS X Lion, and Acrobat X. Hope this is of use to someone. Also runs with Acrobat 9 and Snow Leopard.

Note: Enable access for assistive devices must be enabled, and if using Acrobat 9, the show suffix checkbox in the save dialog needs to be unchecked.

All files are saved with “_enabled” appended to the name.

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 Acrobat Pro"
				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 fileName to my replace_chars(fileName, ".pdf", "_enabled.pdf")
						set value of text field 1 of window "Save As" to fileName
						-- save file
						click button "Save" of window "Save As"
						set windowName to my replace_chars(windowName, ".pdf", "_enabled.pdf")
					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

Is there anything special to get this app working under Mavericks 10.9.4? am having all sorts of bother.

Colly