Preview window titles

Preview window titles seem to always add to the name of the file information about where one is in the document “(page 2 of 5)”. This is useful if one is reading, but I am trying to do GUI scripting of Preview (which is of course[center][/center] not Apple scriptable) and these get in the way – to refer to a window I can’t just use the file name but need to know the page count and in some cases even the size of the window, (since the position actually changes depending on how many pages are displayed – I’m doing 4 x 6 cards so this may be several). The window title does not seems to be changeable with Preview/System Events. Is there any way to get Preview to use just the file name as the window title so I can easily refer to the window in my GUI script?

Model: iMac
AppleScript: 2.7
Browser: Safari 605.1.15
Operating System: macOS 10.14

The Preview.app is scriptable. Here is one example. I tried here control the dimensions of the certain window (I reffered to window with certain name, document and relative file path):


tell application "Preview"
	
	activate
	set theWindowTitle to name of window 1
	set theWindowDoc to document of window 1
	set theWindowFilePath to path of theWindowDoc
	
	set theRefferedWindow to first window whose name is theWindowTitle
	set bounds of theRefferedWindow to {100, 100, 1000, 800}
end tell

return {theWindowTitle, theWindowDoc, theWindowFilePath}

The name of the window (you call it the title) is settable. You can change it (set name of theRefferedWindow to name of theWindowDoc), but what reason? Give us more information, because it is unclear.

FWIW, a suggestion which allows the OP to identify a Preview window by file name for GUI scripting.

set fileName to "Test File.pdf"

tell application "System Events"
	tell process "Preview"
		set theWindow to (first window whose name begins with fileName)
	end tell
end tell

An example of how this might be used in a script.

set fileName to "Test File.pdf"

tell application "System Events"
	tell process "Preview"
		perform action "AXRaise" of (first window whose name begins with fileName)
		-- other GUI scripting
	end tell
end tell

These scripts break easily–for example if Finder is set not to show file extensions–and I would probably try to find a different way to handle this.

BTW, I didn’t understand the OP’s comments regarding the size/position of the Preview window, so perhaps I don’t understand his question.

Thanks, that (first window with name …) actually works quite well in my case since I have available the file name without extension so it doesn’t matter whether the system shows the extension.