I am using this code to get the window title:
tell application "System Events"
set frontApp to name of first application process whose frontmost is true
end tell
tell application frontApp
set window_name to name of front window
end tell
However, this fails in some cases. Obviously it fails when there is no open window but that is Ok. However, in some cases, for example for Texmaker, it fails with an error. It also doesn't work for Preview.
What would be a way to get the window title anyway, even for cases like Texmaker?