We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN 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``



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `kitty/rc/launch.py`
Content:
```
1 #!/usr/bin/env python
2 # License: GPLv3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>
3 
4 
5 from typing import TYPE_CHECKING, Optional
6 
7 from kitty.cli_stub import LaunchCLIOptions
8 from kitty.launch import (
9     launch as do_launch, options_spec as launch_options_spec,
10     parse_launch_args
11 )
12 
13 from .base import (
14     MATCH_TAB_OPTION, ArgsType, Boss, PayloadGetType, PayloadType, RCOptions,
15     RemoteCommand, ResponseType, Window
16 )
17 
18 if TYPE_CHECKING:
19     from kitty.cli_stub import LaunchRCOptions as CLIOptions
20 
21 
22 class Launch(RemoteCommand):
23 
24     '''
25     args+: The command line to run in the new window, as a list, use an empty list to run the default shell
26     match: The tab to open the new window in
27     window_title: Title for the new window
28     cwd: Working directory for the new window
29     env: List of environment variables of the form NAME=VALUE
30     tab_title: Title for the new tab
31     type: The type of window to open
32     keep_focus: Boolean indicating whether the current window should retain focus or not
33     copy_colors: Boolean indicating whether to copy the colors from the current window
34     copy_cmdline: Boolean indicating whether to copy the cmdline from the current window
35     copy_env: Boolean indicating whether to copy the environ from the current window
36     hold: Boolean indicating whether to keep window open after cmd exits
37     location: Where in the tab to open the new window
38     allow_remote_control: Boolean indicating whether to allow remote control from the new window
39     stdin_source: Where to get stdin for thew process from
40     stdin_add_formatting: Boolean indicating whether to add formatting codes to stdin
41     stdin_add_line_wrap_markers: Boolean indicating whether to add line wrap markers to stdin
42     no_response: Boolean indicating whether to send back the window id
43     marker: Specification for marker for new window, for example: "text 1 ERROR"
44     logo: Path to window logo
45     logo_position: Window logo position as string or empty string to use default
46     logo_alpha: Window logo alpha or -1 to use default
47     self: Boolean, if True use tab the command was run in
48     '''
49 
50     short_desc = 'Run an arbitrary process in a new window/tab'
51     desc = (
52         'Prints out the id of the newly opened window. Any command line arguments'
53         ' are assumed to be the command line used to run in the new window, if none'
54         ' are provided, the default shell is run. For example:'
55         ' :code:`kitty @ launch --title=Email mutt`.'
56     )
57     options_spec = MATCH_TAB_OPTION + '\n\n' + '''\
58 --no-response
59 type=bool-set
60 Do not print out the id of the newly created window.
61 
62 
63 --self
64 type=bool-set
65 If specified the tab containing the window this command is run in is used
66 instead of the active tab
67     ''' + '\n\n' + launch_options_spec().replace(':option:`launch', ':option:`kitty @ launch')
68     argspec = '[CMD ...]'
69 
70     def message_to_kitty(self, global_opts: RCOptions, opts: 'CLIOptions', args: ArgsType) -> PayloadType:
71         ans = {'args': args or []}
72         for attr, val in opts.__dict__.items():
73             ans[attr] = val
74         return ans
75 
76     def response_from_kitty(self, boss: Boss, window: Optional[Window], payload_get: PayloadGetType) -> ResponseType:
77         default_opts = parse_launch_args()[0]
78         opts = LaunchCLIOptions()
79         for key, default_value in default_opts.__dict__.items():
80             val = payload_get(key)
81             if val is None:
82                 val = default_value
83             setattr(opts, key, val)
84         tabs = self.tabs_for_match_payload(boss, window, payload_get)
85         if tabs and tabs[0]:
86             w = do_launch(boss, opts, payload_get('args') or [], target_tab=tabs[0])
87             return None if payload_get('no_response') else str(getattr(w, 'id', 0))
88         return None
89 
90 
91 launch = Launch()
92
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

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 @@
             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()

{"golden_diff": "diff --git a/kitty/rc/launch.py b/kitty/rc/launch.py\n--- a/kitty/rc/launch.py\n+++ b/kitty/rc/launch.py\n@@ -81,11 +81,14 @@\n             if val is None:\n                 val = default_value\n             setattr(opts, key, val)\n+        target_tab = None\n         tabs = self.tabs_for_match_payload(boss, window, payload_get)\n         if tabs and tabs[0]:\n-            w = do_launch(boss, opts, payload_get('args') or [], target_tab=tabs[0])\n-            return None if payload_get('no_response') else str(getattr(w, 'id', 0))\n-        return None\n+            target_tab = tabs[0]\n+        elif payload_get('type') not in ('os-window', 'background'):\n+            return None\n+        w = do_launch(boss, opts, payload_get('args') or [], target_tab=target_tab)\n+        return None if payload_get('no_response') else str(getattr(w, 'id', 0))\n \n \n launch = Launch()\n", "issue": "MacOS: Launch OS Window via Remote Control \n**Describe the bug**  \r\n\r\nRef: https://github.com/kovidgoyal/kitty/issues/45#issuecomment-915753960\r\n\r\nRemote control via socket doesn't work opening a new OS window unless there is an existing window open already. \r\n\r\n**To Reproduce**  \r\n\r\nSteps to reproduce the behavior:\r\n1. Launch kitty without window:\r\n````\r\nkitty --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 &\r\n````\r\n2. Attempt to open OS Window using remote control:\r\n````\r\nkitty @ --to unix:/tmp/scratch launch --type=os-window --title=test\r\n````\r\n3. No window opens up\r\n\r\n4. Right click icon -> Open OS Window\r\n\r\n5. Reattempt remote control:\r\n````\r\nkitty @ --to unix:/tmp/scratch launch --type=os-window --title=test\r\n````\r\n6. Window opens up fine with title \"test\"\r\n\r\n**Environment details**\r\n```\r\nkitty 0.25.2 created by Kovid Goyal\r\nDarwin 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\r\nProductName:\tmacOS ProductVersion:\t12.4 BuildVersion:\t21F79\r\nFrozen: True\r\nPaths:\r\n  kitty: /Applications/kitty.app/Contents/MacOS/kitty\r\n  base dir: /Applications/kitty.app/Contents/Resources/kitty\r\n  extensions dir: /Applications/kitty.app/Contents/Resources/Python/lib/kitty-extensions\r\n  system shell: /bin/zsh\r\nLoaded config overrides:\r\n  allow_remote_control yes\r\n  macos_quit_when_last_window_closed no\r\n\r\nConfig options different from defaults:\r\nallow_remote_control y\r\n\r\nImportant environment variables seen by the kitty process:\r\n\tPATH                                /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\r\n\tLANG                                en_AU.UTF-8\r\n\tVISUAL                              nvim\r\n\tEDITOR                              nvim\r\n\tSHELL                               /bin/zsh\r\n\tUSER                                hars\r\n\tXDG_CONFIG_HOME                     /Users/hars/.config\r\n\tXDG_CACHE_HOME                      /Users/hars/.cache\r\n\r\n```\r\n**Additional context**\r\n\r\nAlso tried ``new-window --window-type=os``\r\n\r\n\n", "before_files": [{"content": "#!/usr/bin/env python\n# License: GPLv3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>\n\n\nfrom typing import TYPE_CHECKING, Optional\n\nfrom kitty.cli_stub import LaunchCLIOptions\nfrom kitty.launch import (\n    launch as do_launch, options_spec as launch_options_spec,\n    parse_launch_args\n)\n\nfrom .base import (\n    MATCH_TAB_OPTION, ArgsType, Boss, PayloadGetType, PayloadType, RCOptions,\n    RemoteCommand, ResponseType, Window\n)\n\nif TYPE_CHECKING:\n    from kitty.cli_stub import LaunchRCOptions as CLIOptions\n\n\nclass Launch(RemoteCommand):\n\n    '''\n    args+: The command line to run in the new window, as a list, use an empty list to run the default shell\n    match: The tab to open the new window in\n    window_title: Title for the new window\n    cwd: Working directory for the new window\n    env: List of environment variables of the form NAME=VALUE\n    tab_title: Title for the new tab\n    type: The type of window to open\n    keep_focus: Boolean indicating whether the current window should retain focus or not\n    copy_colors: Boolean indicating whether to copy the colors from the current window\n    copy_cmdline: Boolean indicating whether to copy the cmdline from the current window\n    copy_env: Boolean indicating whether to copy the environ from the current window\n    hold: Boolean indicating whether to keep window open after cmd exits\n    location: Where in the tab to open the new window\n    allow_remote_control: Boolean indicating whether to allow remote control from the new window\n    stdin_source: Where to get stdin for thew process from\n    stdin_add_formatting: Boolean indicating whether to add formatting codes to stdin\n    stdin_add_line_wrap_markers: Boolean indicating whether to add line wrap markers to stdin\n    no_response: Boolean indicating whether to send back the window id\n    marker: Specification for marker for new window, for example: \"text 1 ERROR\"\n    logo: Path to window logo\n    logo_position: Window logo position as string or empty string to use default\n    logo_alpha: Window logo alpha or -1 to use default\n    self: Boolean, if True use tab the command was run in\n    '''\n\n    short_desc = 'Run an arbitrary process in a new window/tab'\n    desc = (\n        'Prints out the id of the newly opened window. Any command line arguments'\n        ' are assumed to be the command line used to run in the new window, if none'\n        ' are provided, the default shell is run. For example:'\n        ' :code:`kitty @ launch --title=Email mutt`.'\n    )\n    options_spec = MATCH_TAB_OPTION + '\\n\\n' + '''\\\n--no-response\ntype=bool-set\nDo not print out the id of the newly created window.\n\n\n--self\ntype=bool-set\nIf specified the tab containing the window this command is run in is used\ninstead of the active tab\n    ''' + '\\n\\n' + launch_options_spec().replace(':option:`launch', ':option:`kitty @ launch')\n    argspec = '[CMD ...]'\n\n    def message_to_kitty(self, global_opts: RCOptions, opts: 'CLIOptions', args: ArgsType) -> PayloadType:\n        ans = {'args': args or []}\n        for attr, val in opts.__dict__.items():\n            ans[attr] = val\n        return ans\n\n    def response_from_kitty(self, boss: Boss, window: Optional[Window], payload_get: PayloadGetType) -> ResponseType:\n        default_opts = parse_launch_args()[0]\n        opts = LaunchCLIOptions()\n        for key, default_value in default_opts.__dict__.items():\n            val = payload_get(key)\n            if val is None:\n                val = default_value\n            setattr(opts, key, val)\n        tabs = self.tabs_for_match_payload(boss, window, payload_get)\n        if tabs and tabs[0]:\n            w = do_launch(boss, opts, payload_get('args') or [], target_tab=tabs[0])\n            return None if payload_get('no_response') else str(getattr(w, 'id', 0))\n        return None\n\n\nlaunch = Launch()\n", "path": "kitty/rc/launch.py"}], "after_files": [{"content": "#!/usr/bin/env python\n# License: GPLv3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>\n\n\nfrom typing import TYPE_CHECKING, Optional\n\nfrom kitty.cli_stub import LaunchCLIOptions\nfrom kitty.launch import (\n    launch as do_launch, options_spec as launch_options_spec,\n    parse_launch_args\n)\n\nfrom .base import (\n    MATCH_TAB_OPTION, ArgsType, Boss, PayloadGetType, PayloadType, RCOptions,\n    RemoteCommand, ResponseType, Window\n)\n\nif TYPE_CHECKING:\n    from kitty.cli_stub import LaunchRCOptions as CLIOptions\n\n\nclass Launch(RemoteCommand):\n\n    '''\n    args+: The command line to run in the new window, as a list, use an empty list to run the default shell\n    match: The tab to open the new window in\n    window_title: Title for the new window\n    cwd: Working directory for the new window\n    env: List of environment variables of the form NAME=VALUE\n    tab_title: Title for the new tab\n    type: The type of window to open\n    keep_focus: Boolean indicating whether the current window should retain focus or not\n    copy_colors: Boolean indicating whether to copy the colors from the current window\n    copy_cmdline: Boolean indicating whether to copy the cmdline from the current window\n    copy_env: Boolean indicating whether to copy the environ from the current window\n    hold: Boolean indicating whether to keep window open after cmd exits\n    location: Where in the tab to open the new window\n    allow_remote_control: Boolean indicating whether to allow remote control from the new window\n    stdin_source: Where to get stdin for thew process from\n    stdin_add_formatting: Boolean indicating whether to add formatting codes to stdin\n    stdin_add_line_wrap_markers: Boolean indicating whether to add line wrap markers to stdin\n    no_response: Boolean indicating whether to send back the window id\n    marker: Specification for marker for new window, for example: \"text 1 ERROR\"\n    logo: Path to window logo\n    logo_position: Window logo position as string or empty string to use default\n    logo_alpha: Window logo alpha or -1 to use default\n    self: Boolean, if True use tab the command was run in\n    '''\n\n    short_desc = 'Run an arbitrary process in a new window/tab'\n    desc = (\n        'Prints out the id of the newly opened window. Any command line arguments'\n        ' are assumed to be the command line used to run in the new window, if none'\n        ' are provided, the default shell is run. For example:'\n        ' :code:`kitty @ launch --title=Email mutt`.'\n    )\n    options_spec = MATCH_TAB_OPTION + '\\n\\n' + '''\\\n--no-response\ntype=bool-set\nDo not print out the id of the newly created window.\n\n\n--self\ntype=bool-set\nIf specified the tab containing the window this command is run in is used\ninstead of the active tab\n    ''' + '\\n\\n' + launch_options_spec().replace(':option:`launch', ':option:`kitty @ launch')\n    argspec = '[CMD ...]'\n\n    def message_to_kitty(self, global_opts: RCOptions, opts: 'CLIOptions', args: ArgsType) -> PayloadType:\n        ans = {'args': args or []}\n        for attr, val in opts.__dict__.items():\n            ans[attr] = val\n        return ans\n\n    def response_from_kitty(self, boss: Boss, window: Optional[Window], payload_get: PayloadGetType) -> ResponseType:\n        default_opts = parse_launch_args()[0]\n        opts = LaunchCLIOptions()\n        for key, default_value in default_opts.__dict__.items():\n            val = payload_get(key)\n            if val is None:\n                val = default_value\n            setattr(opts, key, val)\n        target_tab = None\n        tabs = self.tabs_for_match_payload(boss, window, payload_get)\n        if tabs and tabs[0]:\n            target_tab = tabs[0]\n        elif payload_get('type') not in ('os-window', 'background'):\n            return None\n        w = do_launch(boss, opts, payload_get('args') or [], target_tab=target_tab)\n        return None if payload_get('no_response') else str(getattr(w, 'id', 0))\n\n\nlaunch = Launch()\n", "path": "kitty/rc/launch.py"}]}