# Fix duplicate window when opening from CLI on macOS \(\#48146\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/5be9dc1781ef6d2cbfbdbcd417edd0935cbb83a8)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 5be9dc1781ef6d2cbfbdbcd417edd0935cbb83a8

Requested commit: 5be9dc1781ef6d2cbfbdbcd417edd0935cbb83a8

Commit: 5be9dc1781ef6d2cbfbdbcd417edd0935cbb83a8

Tree: 435f390245f4b673917cfc501a39e3f0d7e332e2

Author: koh-sh

Committer: GitHub

## Message

```
Fix duplicate window when opening from CLI on macOS (#48146)

Closes #47140
Closes #44691

When launching Zed from the CLI (`zed .`), macOS delivers the path as a
`kAEGetURL` Apple Event via Launch Services. Zed relied on the
`application:openURLs:` delegate method to receive this, but its timing
relative to `applicationDidFinishLaunching:` is not guaranteed by macOS.
In release builds, the app reaches `didFinishLaunching` before the URL
is delivered, causing it to be missed and a duplicate window to be
opened. This does not reproduce in debug builds due to slower
initialization, which is why the issue was hard to reproduce from
source.

This replaces `application:openURLs:` with a custom `kAEGetURL` Apple
Event handler registered in `applicationWillFinishLaunching:`. Apple
Events are guaranteed to be delivered synchronously between
`willFinishLaunching` and `didFinishLaunching`, ensuring the URL is
always available before startup logic runs.

 Release Notes:

- Fixed duplicate window creation when opening files/directories from
the CLI on macOS.

Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
```

## Parents

- [fe26ab68094bc731e0d51a8ad94cb00ad6513b5b](https://git.cafe/gitcafe/zed/commit/fe26ab68094bc731e0d51a8ad94cb00ad6513b5b?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/5be9dc1781ef6d2cbfbdbcd417edd0935cbb83a8?format=markdown)
