PDF view scripting....

The pdf view preferences do not appear to be sufficient for my needs. I’m trying to find a way to applescript zooming, but my scripting is, to be kind, quite rusty.

Can somebody kindly tell me why neither of these work, and set me on the right path?

tell application “DEVONthink Pro” to activate
tell application “System Events”
tell process “DEVONthink Pro”
tell menu bar 1
tell menu bar item “View”
tell menu “View”
click menu item “Zoom To Width”
end tell
end tell
end tell
end tell
end tell

OR

tell application “System Events”
tell process “DNtp”
click menu item “Zoom to Width” of menu 1 of menu bar item “View” of menu bar 1
end tell
end tell

Many thanks,

Erik

The first example is on the path toward where you want to go. But why GUI script a menu command that already has a keyboard shortcut?

In either case, here’s a useful page

macosxautomation.com/applesc … scripting/

korm asked: “why GUI script a menu command that already has a keyboard shortcut?”

Because it’s a two-step macro. I want to change the window size as well. I can’t get DTPO to retain either of those settings.

Thanks for the pointer!

Here’s my solution, and how I got it to work:


tell application "DEVONthink Pro"
	activate
	set bounds of think window 1 to {5, 10, 1450, 1200}
	
	tell application "System Events"
		tell process "DEVONthink Pro Office"
			tell menu bar 1
				tell menu bar item "View"
					tell menu "View"
						click menu item "Zoom to Width"
					end tell
				end tell
			end tell
		end tell
	end tell
end tell

This works, but only sporadically, and unpredictably when summoned from within DTPO. I could not figure out what, exactly, was going wrong, whether it’s not focused, or what. It reliably works the first time after I open DTPO, if run from science rip editor. Less reliable in DTPO, and it stops working after a couple of uses.

Then I remembered that UI scripting is often unreliable. So rather than figure out what the script problem is, I got it to work by invoking it with FastScripts. That seems sturdy, at least through 10 minutes of testing.

And, to clarify, the window sizing always works; it’s the zoom that is unreliable.

Thanks again for the help. korm,