From 9989edbe42c7c0b137a580f9ab7b08fe07614410 Mon Sep 17 00:00:00 2001 From: pagedown Date: Sat, 5 Feb 2022 23:19:33 +0800 Subject: [PATCH 1/2] macOS: Add archive file type to info plist List kitty in the Open With menu for archive files. E.g. compressed files or disk image files --- setup.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/setup.py b/setup.py index b609de2c7..47f1e3aea 100755 --- a/setup.py +++ b/setup.py @@ -1006,21 +1006,19 @@ def macos_info_plist() -> bytes: { 'CFBundleTypeName': 'Text files', 'LSItemContentTypes': ['public.text'], - 'LSTypeIsPackage': False, 'CFBundleTypeRole': 'Editor', 'LSHandlerRank': 'Alternate', }, { 'CFBundleTypeName': 'Image files', 'LSItemContentTypes': ['public.image'], - 'LSTypeIsPackage': False, 'CFBundleTypeRole': 'Viewer', 'LSHandlerRank': 'Alternate', }, # Allows dragging arbitrary files to kitty Dock icon, and list kitty in the Open With context menu. { 'CFBundleTypeName': 'All files', - 'LSItemContentTypes': ['public.content', 'public.data'], + 'LSItemContentTypes': ['public.archive', 'public.content', 'public.data'], 'CFBundleTypeRole': 'Editor', 'LSHandlerRank': 'Alternate', }, From 007e9697c42facf548fadfe99b7b50d6dcf04bd4 Mon Sep 17 00:00:00 2001 From: pagedown Date: Sat, 5 Feb 2022 23:20:19 +0800 Subject: [PATCH 2/2] macOS: Add Open with kitty Service There are still some file types that cannot be matched. Add a standalone Open With service. Users can configure shortcut for this service in System Preferences. --- kitty/cocoa_window.m | 13 +++++++++++++ setup.py | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/kitty/cocoa_window.m b/kitty/cocoa_window.m index ae25c170d..bfe25af42 100644 --- a/kitty/cocoa_window.m +++ b/kitty/cocoa_window.m @@ -520,6 +520,19 @@ cocoa_send_notification(PyObject *self UNUSED, PyObject *args) { return YES; } +- (BOOL)openFileURLs:(NSPasteboard*)pasteboard + userData:(NSString *) UNUSED userData error:(NSError **) UNUSED error { + NSDictionary *options = @{ NSPasteboardURLReadingFileURLsOnlyKey: @YES }; + NSArray *urlArray = [pasteboard readObjectsForClasses:[NSArray arrayWithObject:[NSURL class]] options:options]; + for (NSURL *url in urlArray) { + NSString *path = [url path]; + if ([[NSFileManager defaultManager] fileExistsAtPath:path]) { + set_cocoa_pending_action(LAUNCH_URL, [[[NSURL fileURLWithPath:path] absoluteString] UTF8String]); + } + } + return YES; +} + @end // global menu {{{ diff --git a/setup.py b/setup.py index 47f1e3aea..c6a79d7fd 100755 --- a/setup.py +++ b/setup.py @@ -1090,6 +1090,12 @@ def macos_info_plist() -> bytes: 'NSRequiredContext': {'NSTextContent': 'FilePath'}, 'NSSendTypes': ['NSFilenamesPboardType', 'public.plain-text'], }, + { + 'NSMenuItem': {'default': f'Open with {appname}'}, + 'NSMessage': 'openFileURLs', + 'NSRequiredContext': {'NSTextContent': 'FilePath'}, + 'NSSendTypes': ['NSFilenamesPboardType', 'public.plain-text'], + }, ] pl = dict(