We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
For macOS 11+, the following should work to simplify the uti.py code:
import objc from LaunchServices import UTTypeCreatePreferredIdentifierForTag, UTTypeCopyPreferredTagWithClass from Foundation import NSString import CoreServices # import LaunchServices def UTIForExtension(file_extension: str) -> str: if not file_extension: return None # Remove leading dot if included in the extension if file_extension.startswith('.'): file_extension = file_extension[1:] ext = NSString.stringWithString_(file_extension.lower()) # uti = UTTypeCreatePreferredIdentifierForTag(LaunchServices.kUTTagClassFilenameExtension, ext, None) uti = UTTypeCreatePreferredIdentifierForTag(CoreServices.kUTTagClassFilenameExtension, ext, None) return str(uti) if uti else None def PreferredExtensionForUTI(uti_string: str) -> str: if not uti_string: return None uti = NSString.stringWithString_(uti_string) preferred_ext = UTTypeCopyPreferredTagWithClass(uti, CoreServices.kUTTagClassFilenameExtension) return str(preferred_ext) if preferred_ext else None # Example usage: if __name__ == "__main__": uti = UTIForExtension(".jpg") print(f"UTI for .jpg: {uti}") # Output should be: public.jpeg extension = PreferredExtensionForUTI("public.jpeg") print(f"Preferred extension for public.jpeg: {extension}") # Output should be: jpeg uti = UTIForExtension(".mp4") print(f"UTI for .mp4: {uti}") # Output should be: public.jpeg extension = PreferredExtensionForUTI("com.canon.cr2-raw-image") print(f"Preferred extension for com.canon.cr2-raw-image: {extension}") # Output should be: jpeg
The text was updated successfully, but these errors were encountered:
No branches or pull requests
For macOS 11+, the following should work to simplify the uti.py code:
The text was updated successfully, but these errors were encountered: