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