For instance take the following code:
| class AppDelegate: NSObject, NSApplicationDelegate { |
| |
| func applicationDidFinishLaunching(_ aNotification: Notification) { |
| DispatchQueue.main.async { |
| let document = try! NSDocumentController.shared.makeUntitledDocument(ofType: "net.daringfireball.markdown") |
| print(document.fileType!, UTType(document.fileType!)!) |
| NSDocumentController.shared.addDocument(document) |
| document.makeWindowControllers() |
| document.windowControllers[0].window!.title = "Markdown" |
| document.showWindows() |
| } |
| } |
| |
| } |
And Info.plist
:
| <?xml version="1.0" encoding="UTF-8"?> |
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
| <plist version="1.0"> |
| <dict> |
| <key>UTImportedTypeDeclarations</key> |
| <array> |
| <dict> |
| <key>UTTypeConformsTo</key> |
| <array> |
| <string>public.plain-text</string> |
| </array> |
| <key>UTTypeDescription</key> |
| <string>Markdown</string> |
| <key>UTTypeIcons</key> |
| <dict/> |
| <key>UTTypeIdentifier</key> |
| <string>net.daringfireball.markdown</string> |
| <key>UTTypeTagSpecification</key> |
| <dict> |
| <key>public.filename-extension</key> |
| <array> |
| <string>md</string> |
| <string>mdown</string> |
| <string>markdown</string> |
| <string>text</string> |
| </array> |
| <key>public.mime-type</key> |
| <array> |
| <string>text/markdown</string> |
| <string>text/x-markdown</string> |
| <string>text/x-web-markdown</string> |
| </array> |
| </dict> |
| </dict> |
| </array> |
| <key>CFBundleDocumentTypes</key> |
| <array> |
| <dict> |
| <key>CFBundleTypeName</key> |
| <string>Plain Text</string> |
| <key>CFBundleTypeRole</key> |
| <string>Editor</string> |
| <key>LSHandlerRank</key> |
| <string>Default</string> |
| <key>LSItemContentTypes</key> |
| <array> |
| <string>public.plain-text</string> |
| </array> |
| <key>NSDocumentClass</key> |
| <string>$(PRODUCT_MODULE_NAME).Document</string> |
| <key>NSUbiquitousDocumentUserActivityType</key> |
| <string>org.desairem.uFocus.OpenDocument</string> |
| </dict> |
| <dict> |
| <key>CFBundleTypeName</key> |
| <string>Markdown</string> |
| <key>CFBundleTypeRole</key> |
| <string>Editor</string> |
| <key>LSHandlerRank</key> |
| <string>Default</string> |
| <key>LSItemContentTypes</key> |
| <array> |
| <string>net.daringfireball.markdown</string> |
| </array> |
| <key>NSDocumentClass</key> |
| <string>$(PRODUCT_MODULE_NAME).Document</string> |
| <key>NSUbiquitousDocumentUserActivityType</key> |
| <string>org.desairem.uFocus.OpenDocument</string> |
| </dict> |
| </array> |
| </dict> |
| </plist> |
After making sure that the document with the window title Markdown is active, press Command-S to open the default save panel: Plain Text is selected instead of Markdown.