knurling / ServiceStation

Service Station
37 stars 1 forks source link

Menu item associated with Text files not appearing if the file has .md extension #30

Closed VKondakoff closed 4 years ago

VKondakoff commented 4 years ago

Hello!

Just noticed: freshly installed SS does not display menu item associated with Text files if the file has .md extension.

Скриншот 2020-05-05 13 05 59

TextEdit menu item is available for .txt, .rtf and .html files, but not for .md. Bug? Catalina 10.15.4, SS Version 2020.4 (15).

pkamb commented 4 years ago

Can you please press the gear icon and show exactly which Rule predicate is being used?

VKondakoff commented 4 years ago
Скриншот 2020-05-05 13 14 43
VKondakoff commented 4 years ago

Menu item for .md files is not displayed even when there is a Document rule set up (it is displayed for all other documents available):

Скриншот 2020-05-05 13 23 53 Скриншот 2020-05-05 13 25 58
pkamb commented 4 years ago

That's interesting. For me, Markdown files are passing both the Kind rule Text and Document filters in Mojave and Catalina.

Screen Shot 2020-05-05 at 9 36 23 AM

This must be some kind of problem with the Launch Services database, which links UTIs with the associated applications.

Please run mdls someFile.md and post the output.

On my system I see:

kMDItemContentType = "net.daringfireball.markdown"
kMDItemContentTypeTree = (
    "net.daringfireball.markdown",
    "public.item",
    "public.text",
    "public.data",
    "public.content",
    "net.daringfireball.markdown",
    "public.plain-text"
)
VKondakoff commented 4 years ago

Here is what I see:

Скриншот 2020-05-05 20 14 08

Not sure what this means. This system was reinstalled from scratch two weeks ago. The only app, that messed up with .md files was MuseScore which use .md files as MuseData files (https://musescore.org/en/handbook/2/file-formats#musedata). Does MuseScore break something md-related?

pkamb commented 4 years ago

Are those all the keys? kMDItemContentType and kMDItemContentTypeTree are not listed?

Please go through the steps here to register Markdown files with a different app:

VKondakoff commented 4 years ago

I associated .md files with VSCode:

Скриншот 2020-05-05 20 48 00

Here is what I see, when running lsregister -dump:

--------------------------------------------------------------------------------
claim id:           Visual Studio Code document (0x2d54)
localizedNames:     "LSDefaultLocalizedValue" = "Visual Studio Code document"
rank:               Default
bundle:             Code (0xd58)
flags:              relative-icon-path  legacy-wildcard  doc-type (0000000000000034)
roles:              Editor (0000000000000004)
iconFiles:          Contents/Resources/markdown.icns
bindings:           .markdown, .md, .mdoc, .mdown, .mdtext, .mdtxt, .mdwn, .mkd, .mkdn, 'TEXT', 'utxt', 'TUTX', '****'

--------------------------------------------------------------------------------

Now, here is what I see in Terminal, when running mdls:

valerykondakoff@iMac-Valery ~ % mdls /Users/valerykondakoff/Downloads/test.md 
_kMDItemDisplayNameWithExtensions      = "test.md"
kMDItemContentCreationDate             = 2020-05-05 17:44:51 +0000
kMDItemContentCreationDate_Ranking     = 2020-05-05 00:00:00 +0000
kMDItemContentModificationDate         = 2020-05-05 17:55:53 +0000
kMDItemContentModificationDate_Ranking = 2020-05-05 00:00:00 +0000
kMDItemContentType                     = "dyn.ah62d4rv4ge8043a"
kMDItemContentTypeTree                 = (
    "public.item",
    "dyn.ah62d4rv4ge8043a",
    "public.data"
)
kMDItemDateAdded                       = 2020-05-05 17:44:51 +0000
kMDItemDateAdded_Ranking               = 2020-05-05 00:00:00 +0000
kMDItemDisplayName                     = "test.md"
kMDItemDocumentIdentifier              = 0
kMDItemFSContentChangeDate             = 2020-05-05 17:55:53 +0000
kMDItemFSCreationDate                  = 2020-05-05 17:44:51 +0000
kMDItemFSCreatorCode                   = ""
kMDItemFSFinderFlags                   = 0
kMDItemFSHasCustomIcon                 = (null)
kMDItemFSInvisible                     = 0
kMDItemFSIsExtensionHidden             = 0
kMDItemFSIsStationery                  = (null)
kMDItemFSLabel                         = 0
kMDItemFSName                          = "test.md"
kMDItemFSNodeCount                     = (null)
kMDItemFSOwnerGroupID                  = 20
kMDItemFSOwnerUserID                   = 501
kMDItemFSSize                          = 4
kMDItemFSTypeCode                      = ""
kMDItemInterestingDate_Ranking         = 2020-05-05 00:00:00 +0000
kMDItemKind                            = "MuseData File"
kMDItemLastUsedDate                    = 2020-05-05 17:55:47 +0000
kMDItemLastUsedDate_Ranking            = 2020-05-05 00:00:00 +0000
kMDItemLogicalSize                     = 4
kMDItemPhysicalSize                    = 4096
kMDItemUseCount                        = 2
kMDItemUsedDates                       = (
    "2020-05-04 21:00:00 +0000"
)

So, md-documents are interpreted as "MuseData Files" on my system. Is there any way to edit this?

gingerbeardman commented 4 years ago

Interesting, which app has registered the MuseData files as .md?

Regardless, the context menu should now work?

Some options to help with your experience:

  1. use an alternative extension for Markdown files, .markdown, .mdoc, .mdown, .mdtext, .mdtxt, .mdwn, .mkd, .mkdn
  2. remove (or edit the plist of) the app responsible for managing MuseData as .md
VKondakoff commented 4 years ago

This is a MuseScore app: https://musescore.org/. Unfortunately, the SS context menu still does not work for markdown files, even after I uninstalled MuseScore, cleaned it's preferences and restarted the system. I can associate markdown files with any text-editor, but the files are still not counted as text files by the system.

It's interesting, that changing the file extension to .markdown, .mdoc, .mdown, .mdtext, .mdtxt, .mdwn, .mkd, .mkdn does not help as well. The context menu starts to work if I change the extension to .html (for example), but immediately stops if I change it bak to .md or .markdown...

I started a topic on MuseScore support forum: https://musescore.org/en/node/304962 . Let's hope for some additional info.

gingerbeardman commented 4 years ago

Maybe you have to rebuild a database (spotlight? launch services? or something less severe that I do not know right now) after removing the app that registered .md?

Very strange. Here is Markdown working for me.

Screen shot 2020-05-05 at 20 02 08

Screen shot 2020-05-05 at 20 02 59

Screen shot 2020-05-05 at 20 03 41

VKondakoff commented 4 years ago

Thanks for the suggestions, I have rebuild Spotlight index and launch services database and reinstalled SS. The issue is still there. Here is what I see in Terminal now:

valerykondakoff@iMac-Valery ~ % mdls /Users/valerykondakoff/Downloads/test.md
_kMDItemDisplayNameWithExtensions      = "test.md"
kMDItemContentCreationDate             = 2020-05-05 17:44:51 +0000
kMDItemContentCreationDate_Ranking     = 2020-05-05 00:00:00 +0000
kMDItemContentModificationDate         = 2020-05-05 17:55:53 +0000
kMDItemContentModificationDate_Ranking = 2020-05-05 00:00:00 +0000
kMDItemContentType                     = "dyn.ah62d4rv4ge8043a"
kMDItemContentTypeTree                 = (
    "public.item",
    "dyn.ah62d4rv4ge8043a",
    "public.data"
)
kMDItemDateAdded                       = 2020-05-05 17:44:51 +0000
kMDItemDateAdded_Ranking               = 2020-05-05 00:00:00 +0000
kMDItemDisplayName                     = "test.md"
kMDItemDocumentIdentifier              = 0
kMDItemFSContentChangeDate             = 2020-05-05 17:55:53 +0000
kMDItemFSCreationDate                  = 2020-05-05 17:44:51 +0000
kMDItemFSCreatorCode                   = ""
kMDItemFSFinderFlags                   = 0
kMDItemFSHasCustomIcon                 = (null)
kMDItemFSInvisible                     = 0
kMDItemFSIsExtensionHidden             = 0
kMDItemFSIsStationery                  = (null)
kMDItemFSLabel                         = 0
kMDItemFSName                          = "test.md"
kMDItemFSNodeCount                     = (null)
kMDItemFSOwnerGroupID                  = 20
kMDItemFSOwnerUserID                   = 501
kMDItemFSSize                          = 4
kMDItemFSTypeCode                      = ""
kMDItemInterestingDate_Ranking         = 2020-05-05 00:00:00 +0000
kMDItemKind                            = "Visual Studio Code document"
kMDItemLastUsedDate                    = 2020-05-05 17:55:47 +0000
kMDItemLastUsedDate_Ranking            = 2020-05-05 00:00:00 +0000
kMDItemLogicalSize                     = 4
kMDItemPhysicalSize                    = 4096
kMDItemUseCount                        = 7
kMDItemUsedDates                       = (
    "2020-05-04 21:00:00 +0000"
)
valerykondakoff@iMac-Valery ~ % 
pkamb commented 4 years ago

To get the Kind is Markdown behavior, Service Station is internally testing that the file's UTI conforms to the UTI string "net.daringfireball.markdown".

So unless/until you get that string into the kMDItemContentTypeTree it will not work.

dyn.ah62d4rv4ge8043a is a dynamic UTI, which means it is not known by your system.

I would expect TextMate or some other app on your system to declare the Markdown UTI. But perhaps not. Try installing BBEdit, which almost certainly will. Set that app to open .md files, possibly reset Launch Services and/or restart. Markdown should then be recognized.

Service Station may be able to declare file types in its own bundle, which would remove the need for the other app to do so. I'll look into that, similar to this change here: https://github.com/toland/qlmarkdown/issues/3

gingerbeardman commented 4 years ago

Interestingly, I have BBEdit and TextMate and more installed and I see:

kMDItemContentType                 = "net.daringfireball.markdown"
kMDItemKind                        = "Markdown Document"
Details ``` $ mdls license.md kMDItemContentCreationDate = 2020-05-05 17:30:38 +0000 kMDItemContentCreationDate_Ranking = 2020-05-05 00:00:00 +0000 kMDItemContentModificationDate = 2020-05-05 17:30:38 +0000 kMDItemContentType = "net.daringfireball.markdown" kMDItemContentTypeTree = ( "net.daringfireball.markdown", "public.item", "public.text", "public.data", "public.content", "net.daringfireball.markdown", "public.plain-text" ) kMDItemDateAdded = 2020-05-05 18:41:35 +0000 kMDItemDateAdded_Ranking = 2020-05-05 00:00:00 +0000 kMDItemDisplayName = "license.md" kMDItemFSContentChangeDate = 2020-05-05 17:30:38 +0000 kMDItemFSCreationDate = 2020-05-05 17:30:38 +0000 kMDItemFSCreatorCode = "" kMDItemFSFinderFlags = 0 kMDItemFSHasCustomIcon = (null) kMDItemFSInvisible = 0 kMDItemFSIsExtensionHidden = 0 kMDItemFSIsStationery = (null) kMDItemFSLabel = 0 kMDItemFSName = "license.md" kMDItemFSNodeCount = (null) kMDItemFSOwnerGroupID = 20 kMDItemFSOwnerUserID = 501 kMDItemFSSize = 226 kMDItemFSTypeCode = "" kMDItemInterestingDate_Ranking = 2020-05-05 00:00:00 +0000 kMDItemKind = "Markdown Document" kMDItemLogicalSize = 226 kMDItemPhysicalSize = 4096 ```
VKondakoff commented 4 years ago

Success! I was able to restore the default UTI by associating .md files with Bear notes app markdown editor, rebuilding Launch Services database and resetting Spotlight indexes. Here is what I see after system restart:

_kMDItemDisplayNameWithExtensions      = "test.md"
kMDItemContentCreationDate             = 2020-05-05 17:44:51 +0000
kMDItemContentCreationDate_Ranking     = 2020-05-05 00:00:00 +0000
kMDItemContentModificationDate         = 2020-05-05 17:55:53 +0000
kMDItemContentModificationDate_Ranking = 2020-05-05 00:00:00 +0000
kMDItemContentType                     = "net.daringfireball.markdown"
kMDItemContentTypeTree                 = (
    "net.daringfireball.markdown",
    "public.plain-text",
    "public.text",
    "public.data",
    "public.item",
    "public.content"
)
kMDItemDateAdded                       = 2020-05-05 17:44:51 +0000
kMDItemDateAdded_Ranking               = 2020-05-05 00:00:00 +0000
kMDItemDisplayName                     = "test.md"
kMDItemDocumentIdentifier              = 0
kMDItemFSContentChangeDate             = 2020-05-05 17:55:53 +0000
kMDItemFSCreationDate                  = 2020-05-05 17:44:51 +0000
kMDItemFSCreatorCode                   = ""
kMDItemFSFinderFlags                   = 0
kMDItemFSHasCustomIcon                 = 0
kMDItemFSInvisible                     = 0
kMDItemFSIsExtensionHidden             = 0
kMDItemFSIsStationery                  = 0
kMDItemFSLabel                         = 0
kMDItemFSName                          = "test.md"
kMDItemFSNodeCount                     = 4
kMDItemFSOwnerGroupID                  = 20
kMDItemFSOwnerUserID                   = 501
kMDItemFSSize                          = 4
kMDItemFSTypeCode                      = ""
kMDItemInterestingDate_Ranking         = 2020-05-06 00:00:00 +0000
kMDItemKind                            = "Markdown"
kMDItemLastUsedDate                    = 2020-05-06 09:16:22 +0000
kMDItemLastUsedDate_Ranking            = 2020-05-06 00:00:00 +0000
kMDItemLogicalSize                     = 4
kMDItemPhysicalSize                    = 4096
kMDItemUseCount                        = 1
kMDItemUsedDates                       = (
    "2020-05-05 21:00:00 +0000"
)

And SS works with .md files as expected now. And .md files are back in the search resulted, when searching by 'Kind: text' criteria.

Thanks to @gingerbeardman and @pkamb for useful suggestions. Now I know much more about handling of content kind in macOS...

pkamb commented 4 years ago

Glad you got that working! Ratings and Reviews in the Mac App Store much appreciated :)