Repository: kovidgoyal/kitty

Issue:
MacOS: Launch OS Window via Remote Control 
**Describe the bug**  

Ref: https://github.com/kovidgoyal/kitty/issues/45#issuecomment-915753960

Remote control via socket doesn't work opening a new OS window unless there is an existing window open already. 

**To Reproduce**  

Steps to reproduce the behavior:
1. Launch kitty without window:
````
kitty --config NONE --listen-on=unix:/tmp/scratch -o allow_remote_control=yes -o macos_quit_when_last_window_closed=no -1 --instance-group scratch false &
````
2. Attempt to open OS Window using remote control:
````
kitty @ --to unix:/tmp/scratch launch --type=os-window --title=test
````
3. No window opens up

4. Right click icon -> Open OS Window

5. Reattempt remote control:
````
kitty @ --to unix:/tmp/scratch launch --type=os-window --title=test
````
6. Window opens up fine with title "test"

**Environment details**
```
kitty 0.25.2 created by Kovid Goyal
Darwin gtd.lan 21.5.0 Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:22 PDT 2022; root:xnu-8020.121.3~4/RELEASE_X86_64 x86_64
ProductName:	macOS ProductVersion:	12.4 BuildVersion:	21F79
Frozen: True
Paths:
  kitty: /Applications/kitty.app/Contents/MacOS/kitty
  base dir: /Applications/kitty.app/Contents/Resources/kitty
  extensions dir: /Applications/kitty.app/Contents/Resources/Python/lib/kitty-extensions
  system shell: /bin/zsh
Loaded config overrides:
  allow_remote_control yes
  macos_quit_when_last_window_closed no

Config options different from defaults:
allow_remote_control y

Important environment variables seen by the kitty process:
	PATH                                /usr/local/opt/coreutils/libexec/gnubin:/Users/hars/.config/bin:/Users/hars/.dwm/statusbar:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/usr/local/opt/coreutils/libexec/gnubin:/Users/hars/.config/bin:/Users/hars/.dwm/statusbar:/Applications/kitty.app/Contents/MacOS:/Users/hars/.local/share/sheldon/repos/github.com/kazhala/dotbare:/usr/local/opt/fzf/bin
	LANG                                en_AU.UTF-8
	VISUAL                              nvim
	EDITOR                              nvim
	SHELL                               /bin/zsh
	USER                                hars
	XDG_CONFIG_HOME                     /Users/hars/.config
	XDG_CACHE_HOME                      /Users/hars/.cache

```
**Additional context**

Also tried ``new-window --window-type=os``




Discussion:

Resolving patch:
diff --git a/kitty/rc/launch.py b/kitty/rc/launch.py
--- a/kitty/rc/launch.py
+++ b/kitty/rc/launch.py
@@ -81,11 +81,14 @@ def response_from_kitty(self, boss: Boss, window: Optional[Window], payload_get:
             if val is None:
                 val = default_value
             setattr(opts, key, val)
+        target_tab = None
         tabs = self.tabs_for_match_payload(boss, window, payload_get)
         if tabs and tabs[0]:
-            w = do_launch(boss, opts, payload_get('args') or [], target_tab=tabs[0])
-            return None if payload_get('no_response') else str(getattr(w, 'id', 0))
-        return None
+            target_tab = tabs[0]
+        elif payload_get('type') not in ('os-window', 'background'):
+            return None
+        w = do_launch(boss, opts, payload_get('args') or [], target_tab=target_tab)
+        return None if payload_get('no_response') else str(getattr(w, 'id', 0))
 
 
 launch = Launch()


Test patch: