set theWindows to windows
repeat with eachWindow in theWindows
set windowName to name of eachWindow
if windowName contains "Settings" then
close eachWindow
end if
end repeat
end tell
My main thought is: is there a reason you're not using OSC to trigger cues from the Streamdeck? That would be my go-to.
Finally, this script should quit Qlab whether or not the settings window is open:
tell application "QLab"
quit saving no
end tell