Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MacOS Get default application for file type

Tags:

macos

I am working on a Mac app. I ultimately want to use default app icons within my app. From the Info.plist and the Resource folder of an app I can get the .icns file and convert that to the image format I need. But I need to know the default application associated with the particular file extension, if any.

So how to get the default application that the system currently associates with a given file extension?

like image 524
FeelTheRain Avatar asked Oct 15 '25 14:10

FeelTheRain


2 Answers

Don't go digging in other apps' bundles. It's always best to work at the level of abstraction that suits the question you want to ask. If you want to get the icon that the Finder (or a Mail attachment, etc) would display for a file of a particular type, use the NSWorkspace iconForFileType: method.

like image 133
rickster Avatar answered Oct 19 '25 12:10

rickster


I think what you're looking for is part of the OSX Launch Services: LSCopyDefaultApplicationURLForContentType API. This returns the info on apps that can open specific Uniform Type Identifiers. There's also a similar API called LSCopyDefaultApplicationURLForURL to check which app opens a specific known file.

like image 27
Cahit Avatar answered Oct 19 '25 13:10

Cahit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!