Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS: drag-n-drop folder into the app icon #6456

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

catlan
Copy link

@catlan catlan commented Dec 4, 2024

This implements #3975: macOS: drag-n-drop folder into the app icon

This requires in the Info.plist to expand the CFBundleDocumentTypes array (copied the parts of the definition from Terminal.app/Contents/Info.plist). With this in place, the application:openFile: gets called. I copied the existing OpenCommandScript code and adapted it.

This enables to open folders by drag-n-drop into the app icon, most commonly when in the Dock. But it also allows other applications to open wezterm at a certain directory.

Example Script:

# opens that directory in WezTerm (Path)
open -a ~/Downloads/WezTerm-macos-20240203-110809-5046fc22/WezTerm.app ~/Downloads/WezTerm-macos-20240203-110809-5046fc22

# opens that directory in WezTerm (Bundle ID)
open -b com.github.wez.wezterm ~/Downloads/WezTerm-macos-20240203-110809-5046fc22

Example Objective-C:

NSWorkspace *workspace = NSWorkspace.sharedWorkspace;
NSURL *appURL = [workspace URLForApplicationWithBundleIdentifier:@"com.github.wez.wezterm"];
if (appURL) {
	NSWorkspaceOpenConfiguration *configuration = [NSWorkspaceOpenConfiguration configuration];
	[workspace openURLs:@[url] withApplicationAtURL:appURL configuration:configuration completionHandler:^(NSRunningApplication *application, NSError *error) {
		if (error) {
			completionHandler(NO, error);
		} else {
			completionHandler(YES, nil);
		}
	}];
}

Todo:

  • When WezTerm is launched with a directory to open, only open one window with the directory as cwd. Currently the default window opens and a window with the directory as cwd. I don't have a rust dev env, so I can't debug this.

There is no work done in applicationWillFinishLaunching: or  applicationDidFinishLaunching:.

But if the user started up the application by double-clicking a file, the delegate receives the application:openFile: message before receiving applicationDidFinishLaunching:.

So for this to work I removed launched ivar and its checks
Perviously the launched ivar guarded that only one window was created.

Now use the window count
applicationOpenUntitledFile: is called when application:openFile: returns NO
@catlan catlan changed the title #3975: macOS: drag-n-drop folder into the app icon macOS: drag-n-drop folder into the app icon Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant