See this ObjectiveC code below from Robert Lindsay send through users mailing list to get a list of macOS application from a file extension. GUI must provide a dialog to show this list and allow user to select right one. Code explain also how to call macOS SDK to invoke target application. // --------------------------------- // given a filename extension "extension", here's how to find all of the // applications known to the OS who can open files of that type. CFStringRef uti = NULL; CFArrayRef bundleIDs = NULL; CFMutableArrayRef applications = NULL; applications = CFArrayCreateMutable(kCFAllocatorDefault, 0); // Make a UTI from a filename extension uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, extension, nil); if (NULL != uti) { // get a list of all of the application bundle IDs that know how to handle this: bundleIDs = LSCopyAllRoleHandlersForContentType(uti, kLSRolesViewer | kLSRolesEditor); } if (NULL != bundleIDs) { // find all the available applications with this bundle ID // getting the display name and version is left as an exercise for the reader. const CFIndex count = CFArrayGetCount(bundleIDs); for (CFIndex i = 0; i < count; i++) { CFArrayRef appsForBundleID = NULL; appsForBundleID = LSCopyApplicationURLsForBundleIdentifier(bundleID, NULL); if (NULL != appsForBundleID) { // // you could call CFURLResourceIsReachable() on each item before adding // it to the big array of qualified applications. // CFArrayAppendArray(applications, appsForBundleID, CFRangeMake(0, CFArrayGetCount(appsForBundleID))); CFRelease(appsForBundleID); } } } // "applications" now has an array of ALL of the possible applications // when finished. Given a UI to choose one, you can then call // LSOpenFromURLSpec() to open your file with a specific application. // when you're finished, don't forget to release the resources or you'll leak memory CFRelease(uti); CFRelease(bundleIDs); CFRelease(applications); // ------------------------------ Gilles Caulier
Git commit 061d3397e926f536102dc986c0db86a1bf266288 by Gilles Caulier. Committed on 03/01/2022 at 09:04. Pushed by cgilles into branch 'master'. Start to include codes from Robert Lindsay to handle OpenWith actions under MacOS CCMAIL: robert.lindsay@gmail.com A +86 -0 core/app/items/utils/appsforfileextension.mm M +3 -3 core/libs/notificationmanager/macnotification.mm https://invent.kde.org/graphics/digikam/commit/061d3397e926f536102dc986c0db86a1bf266288
Git commit 5e79ae5febfd4a4354c32ac2551195b029331f0a by Gilles Caulier. Committed on 04/01/2022 at 13:28. Pushed by cgilles into branch 'master'. Now this function return a list of MacOS bundle urls properly. M +35 -208 core/app/items/utils/appsforfileextension.mm M +8 -8 core/tests/fileio/appforfileextension_cli.cpp https://invent.kde.org/graphics/digikam/commit/5e79ae5febfd4a4354c32ac2551195b029331f0a
Git commit 96f6cf9a0ac665255d0e1277850fcf1c6dcbc70f by Gilles Caulier. Committed on 04/01/2022 at 14:35. Pushed by cgilles into branch 'master'. Implement MacOS open with bundle application low level method M +36 -0 core/app/items/utils/appsforfileextension.mm https://invent.kde.org/graphics/digikam/commit/96f6cf9a0ac665255d0e1277850fcf1c6dcbc70f
Git commit 6264d320c28dfa16b4cdfdbe49d872a3666190b5 by Gilles Caulier. Committed on 04/01/2022 at 15:07. Pushed by cgilles into branch 'master'. new cli tool to open file with default MAcOS applucation bundle M +12 -1 core/tests/fileio/CMakeLists.txt M +14 -13 core/tests/fileio/appforfileextension_cli.cpp A +71 -0 core/tests/fileio/openfilewithapplication_cli.cpp [License: GPL (v2+)] https://invent.kde.org/graphics/digikam/commit/6264d320c28dfa16b4cdfdbe49d872a3666190b5
Git commit ef57823d65df593194f4fdfc58ed025c6f7221e6 by Gilles Caulier. Committed on 04/01/2022 at 15:45. Pushed by cgilles into branch 'master'. Move MAcOS code for OpenWith feature in DServiceMenu class M +0 -7 core/app/DigikamGuiTarget.cmake M +4 -1 core/app/items/utils/contextmenuhelper.cpp M +7 -0 core/libs/threadimageio/CMakeLists.txt M +2 -2 core/libs/threadimageio/engine/dservicemenu.cpp M +13 -5 core/libs/threadimageio/engine/dservicemenu.h R +0 -0 core/libs/threadimageio/engine/dservicemenu_mac.mm [from: core/app/items/utils/appsforfileextension.mm - 100% similarity] M +8 -10 core/tests/fileio/CMakeLists.txt R +7 -6 core/tests/fileio/macappforfileextension_cli.cpp [from: core/tests/fileio/appforfileextension_cli.cpp - 083% similarity] R +4 -4 core/tests/fileio/macopenfilewithapplication_cli.cpp [from: core/tests/fileio/openfilewithapplication_cli.cpp - 087% similarity] https://invent.kde.org/graphics/digikam/commit/ef57823d65df593194f4fdfc58ed025c6f7221e6
Git commit cf443e7fd6c5b9a6a20007f46d02ce30b1e7bc64 by Gilles Caulier. Committed on 04/01/2022 at 16:21. Pushed by cgilles into branch 'master'. add new method to get common MacOS Application bundle urls for a given list of files to open M +2 -0 core/app/items/utils/contextmenuhelper.cpp M +1 -0 core/libs/threadimageio/engine/dservicemenu.h M +31 -0 core/libs/threadimageio/engine/dservicemenu_mac.mm https://invent.kde.org/graphics/digikam/commit/cf443e7fd6c5b9a6a20007f46d02ce30b1e7bc64
Git commit 8493c9d8e3235ada8c3ffd63ed540f170cecbec4 by Gilles Caulier. Committed on 04/01/2022 at 17:23. Pushed by cgilles into branch 'master'. MacOS: Append Open With option in generic digiKam context menu. M +33 -2 core/app/items/utils/contextmenuhelper.cpp M +1 -1 core/libs/threadimageio/engine/dservicemenu.h M +12 -16 core/libs/threadimageio/engine/dservicemenu_mac.mm M +1 -1 core/tests/fileio/macopenfilewithapplication_cli.cpp https://invent.kde.org/graphics/digikam/commit/8493c9d8e3235ada8c3ffd63ed540f170cecbec4
TODO : - Add Icons in OpenWith context menu for each application bundle found. - Add an option to open the MacOS open with dialog. - Handle open with default application under MacOS in Image Editor/Showfoto. Gilles Caulier
Git commit 78f4ca12573249081022652d517fe865609afe69 by Gilles Caulier. Committed on 04/01/2022 at 19:28. Pushed by cgilles into branch 'master'. New method to get MacOS Application bundle name M +1 -1 core/app/items/utils/contextmenuhelper.cpp M +1 -0 core/libs/threadimageio/engine/dservicemenu.h M +5 -0 core/libs/threadimageio/engine/dservicemenu_mac.mm M +2 -2 core/tests/fileio/macopenfilewithapplication_cli.cpp https://invent.kde.org/graphics/digikam/commit/78f4ca12573249081022652d517fe865609afe69
this is
Hi Robert and Happy new year, With the build of digiKam package for MacOS from today, this the how OpenWith context menu is show : https://i.imgur.com/gDQ64ap.png Compared with the Apple Finder file browser : https://i.imgur.com/JJLH3sm.png As you can see the main feature is here, but it miss the Application icon and the "Other" menu entry. I must admit that Objective-C is a big pain for me but i arrive to manage a little bit. Switf language is really a complexity and mostly unreadable for a long time developer like me. I don't understand how a company as Apple can promote a language like this. But it's another story. The resources on the web about Apple example and development is also a big hole. I pass a lots of time to read few words and understand a simple feature. So help are welcome here to : - get installed Application bundle icons using Application url. - open the Open With dialog to let's user to select right application from the list of installed one. Note: current code to handle Open With under MacOS is located in the file from digiKam core : https://invent.kde.org/graphics/digikam/-/blob/master/core/libs/threadimageio/engine/dservicemenu_mac.mm Best regards Gilles Caulier
Git commit 1daf9090608b11a60bcf0fbf9748572906865d21 by Gilles Caulier. Committed on 05/01/2022 at 17:59. Pushed by cgilles into branch 'master'. new method to get MacOS Application bundle icon M +2 -0 core/libs/threadimageio/engine/dservicemenu.h M +23 -0 core/libs/threadimageio/engine/dservicemenu_mac.mm M +0 -1 core/tests/fileio/CMakeLists.txt https://invent.kde.org/graphics/digikam/commit/1daf9090608b11a60bcf0fbf9748572906865d21
Voilà : now MacOS openWith context menu show Application bundle icons... https://i.imgur.com/5Hq4dEv.png Gilles Caulier
Git commit 30b93a1b7c15e51c9b357431feff41ee5292aabc by Gilles Caulier. Committed on 06/01/2022 at 05:07. Pushed by cgilles into branch 'master'. Separate Info.plish for digiKam and Showfoto. Add lisy of Showfoto open type mimes support in Info.plist. Now Showfoto must be availalble as alternate Application bundle to open images under MacOS. FIXED-IN: 7.5.0 M +1 -1 core/app/DigikamTarget.cmake R +0 -0 core/cmake/templates/DigikamInfo.plist.cmake.in [from: core/cmake/templates/Info.plist.cmake.in - 100% similarity] A +173 -0 core/cmake/templates/ShowfotoInfo.plist.cmake.in M +1 -1 core/showfoto/CMakeLists.txt https://invent.kde.org/graphics/digikam/commit/30b93a1b7c15e51c9b357431feff41ee5292aabc
Showfoto is now available officially as image editor in MacOS context menu. Look the screenshot from Apple Finder : https://i.imgur.com/hJpoR0t.png Gilles Caulier