Script for auto position and zoom (for pdf) document window

I am trying a write a simple toolbar script which will position any opened document window at the center of my screen with size matching an A4 sheet and automatically zoom to width (zoom is for pdf only). Somehow I can never send the ctrl-cmd-w key stroke by system events. I am just wondering what mistake/s I have made in the script?

BTW, I found a free app “icons8 Lite” which offers a good number of icons which can be handy in assigning new/different look to any script/group/tag in Devonthink. Hope it helps.

Thank you very much in advance
George


set {screenWidth, screenHeight} to {3840, 2160} -- full screen size of monitor
set {winHeight, winWidth} to {1600, 1150} -- match the actual size of A4 paper for a 32 inch mon with resolution of 3840*2160
set yAxis to (screenHeight - winHeight) / 2 -- align the open document at the center of the screen
set xAxis to (screenWidth  - winWidth)/2 -- align the open document to the center of the screen
tell application id "DNtp"
	
	set bounds of window 1 to {xAxis, yAxis, xAxis + winWidth, yAxis + winHeight}
	
	tell application "System Events"
		keystroke "w" using {control down, command down}
	end tell
	
end tell

1 Like

This forum is a treasure for self-learner. I just dig deeper into older post and found that all I need to do is to add a delay in the “System Events”. Thanks again.