scripting Acrobat, Preview, something

I’d like to have a one-click method of applying a text header (“final” “approved”, etc) applied to every page of a PDF.

I have Acrobat 7 Pro, as well as Preview (Tiger version).

Acrobat seems to be scriptable, but I don’t see anywhere within the dictionary a reference to headers/footers, watermarks, etc

Ironically, Preview doesn’t seem to be Applescriptable at all.

I do see a few Automator actions for PDF manipulation, but nothing relating to headers.
(There is a watermark action, but I need header actions)

Am I really this up-a-creek?

(please don’t tell me to learn javascript)

You can do this via GUI scripting, but depending on a number of factors you are going to have to play with the timing and the delay statements. This script will add a header to the currently open PDF and then save & close overwriting the original. Hopefully it can get you started.

(*
	Left Header Set 	- set value of text area 1 of scroll area 2 of window "Add Header and Footer" to headerText
	Center Header Set 	- set value of text area 1 of scroll area 3 of window "Add Header and Footer" to headerText
	Right Header Set	- set value of text area 1 of scroll area 4 of window "Add Header and Footer" to headerText
*)

--
set headerText to "approved"
--

activate application "Adobe Acrobat Professional"
tell application "System Events"
	tell process "Acrobat"
		click menu item "Add..." of menu 1 of menu item "Header & Footer" of menu 1 of menu bar item "Document" of menu bar 1
		delay 5
		set value of text area 1 of scroll area 3 of window "Add Header and Footer" to headerText
		delay 5
		click button "OK" of window "Add Header and Footer"
		delay 10
	end tell
end tell

tell application "Adobe Acrobat Professional" to close front document saving yes

I’m actually trying to do it thru the Batch Process menu item (under “Advanced”)
(That way I can predetermine font and font size)
but I get bottlenecked when trying to get Sys Events to pick from the list of Batch sequences (a scroll menu).
See code below:

But I’m curious how you determined " text area 1 of scroll area 3"?
Is that something I could get from using UI inspector?

Thank you very much in any case…

tell application "Adobe Acrobat 7.0 Professional" to activate
tell application "System Events"
	tell process "Acrobat"
		tell menu bar 1
			tell menu "Advanced" of menu bar item "Advanced"
				click menu item "Batch Processing..."
				tell application "System Events"
					tell window "Batch Sequences" of process "Acrobat"
						delay 0.5
						--tell button -5 to perform action "AXPress"
					end tell
				end tell
			end tell
		end tell
	end tell
end tell

Hmm, I suppose I should have been more careful when I read your original post. I am limited to working with Acrobat Pro version 8 or 9. To answer your question though yes I was able to find the text area thru UI Inspector. At least when looking at version 8/9 of Acrobat.

As to your other question I can’t seem to be able to click a batch script via GUI scripting in Acrobat 9 because the window is some weird floating module thing I’m having trouble directly referencing.

For what it’s worth though you can, again in Acro 8, set the font and font size in the method I originally posted.

I’ll try again when I get to work tomorrow. Thanks for your persistence.

James,
Writing this at 11:30 pm
I was able to try your code in v8, and it worked like a charm.
So I’m excited, I feel like its just a question of fooling with the syntax in v7.
I’m actually looking forward to going to work tomorrow…

Hopefully you can get it sorted out, but if not I think I might have a copy of v7 floating around my office. If I have time I can install that and take a look.

Okay I had some time this morning and installed Acrobat 7 on my laptop and got it to work. Let me know if you want me to post the code or if you want to play around with it first.

Nertz.

Can’t get past this line:

click menu item “Add Header and Footers…” of menu 1 of menu bar item “Document” of menu bar 1

Here’s what UI Inspector’s showing me:

<AXApplication: “Acrobat”>

<AXMenuBarItem: “Document”>

<AXMenuItem: “Add Headers & Footers…”>

I guess I wonder if the snag is the “of menu 1” after “Add Headers and Footers…”

I’ll admit, I’m fishing…

Here is what I got working

(*
   Left Header Set    	- set value of text field 3 of group 1 of group 1 of group 1 of tab group 1 of group 1 of window "Add Headers & Footers" to headerText
   Center Header Set    	- set value of text field 2 of group 1 of group 1 of group 1 of tab group 1 of group 1 of window "Add Headers & Footers" to headerText
   Right Header Set    	- set value of text field 1 of group 1 of group 1 of group 1 of tab group 1 of group 1 of window "Add Headers & Footers" to headerText
*)

--
set headerText to "approved"
--

activate application "Adobe Acrobat 7.0 Professional"
tell application "System Events"
	tell process "Acrobat"
		click menu item "Add Headers & Footers..." of menu 1 of menu bar item "Document" of menu bar 1
		delay 5
		set value of text field 2 of group 1 of group 1 of group 1 of tab group 1 of group 1 of window "Add Headers & Footers" to headerText
		delay 5
		click button "OK" of group 1 of window "Add Headers & Footers"
		delay 10
	end tell
end tell

tell application "Adobe Acrobat 7.0 Professional" to close front document saving yes

How…

I never woulda guessed, but there it was:

set value of text field 2 of group 1 of group 1 of group 1 of tab group 1 of group 1 of window “Add Headers & Footers” to headerText

and just like UI Insp. says:

<AXApplication: “Acrobat”>
<AXWindow: “Add Headers & Footers”>





Hehe, GUI scripting can be a annoying beast to tame at times :smiley:

Instead of UI Inspector, I find PreFab’s UI Browser more clear. In the past it has helped me figure out how to access things that confused UI Inspector.

But then again, I paid good money for, and prefer, FaceSpan rather than use Xcode too…go figure. :wink:

And yes, UI scripting is incredibly annoying…always remember that “delay” is your best friend when playing with UI scripting.

I too am a huge fan of UI Inspector, but I am totally going to have to disagree with you on FaceSpan over Xcode :stuck_out_tongue: