Get current app from two instances with same name by Apple Script How to address an active window of an active app by AppleScript when two instances of the same app are running?

The script below addresses the other app. Probably because the name and id of the app is the same and it picks just the first one from the list by name. 

tell application (path to frontmost application as text) to tell front window...


I use that script to maximize the current window but it does not work for the two instances of the same app:

tell application "Finder" to set {0, 0, dtw, dth} to bounds of window of desktop
try
    tell application (path to frontmost application as text) to tell front window
        set bounds to {0, 0, dtw, dth}
    end tell
on error
    tell application "System Events" to tell (process 1 where it is frontmost)
        try
            click (button 1 of window 1 where subrole is "AXZoomButton")
        end try
    end tell
end try
It's not possible to get the right instance of the frontmost application because these two instances have the same path and the same bundle identifier, the application will always be the first open instance. 

You must use the frontmost process, like this:

tell application "System Events"
    tell (first process whose frontmost is true) to tell front window to if exists then
        set position to {0, 0}
        set size to {dtw, dth}
    end if
end tell