Updated to avoid using windows with empty names, this can cause to applescript error.