Moving window specified by process id

Ok, I’m doing something wrong again…

set thePID to 2079

tell application "System Events"
	set frontmost of every process whose unix id is thePID to true --bring it to the front
	tell process id thePID
		set position of window 1 to {300, 300}
	end tell
end tell

I need to specify by process id, due to the possibility of having multiple instances of the app running. For example, two videos playing simultaneously in VLC. I can get the pid of each instance, I just have it set directly for testing purposes.

The error is
System Events got an error: Can’t set process id 2079 to {300, 300}." number -10006 from process id 2079

This is happening in the “set position” line. I figure it has to do with how it’s worded. All the examples I find refer to specifying the app name. I have tried this and it does work when using “VLC”, but does not behave correctly when two instances are running.

Maybe there is another way that I’m not realizing? Help please! :slight_smile:

Edit - I should mention that the title of the window can change as well, so can’t really go by that either…

Well, found it…

set thePID to 2079

tell application "System Events"
	set frontmost of every process whose unix id is thePID to true --bring it to the front
	
	tell (first process whose unix id is thePID)
		set position of window 1 to {300, 300}
		set position of window 1 to {300, 300}
	end tell
end tell

Bonus question, why do I have to tell it to move the window twice? My setup is two monitors, with the primary on the right. Not too worried about it, since I have a work around…