0

I have two text files with no extension and made them executable. Both are set to open with Terminal app. However one file is shown as kind "Text" and the other one as "executeable unix file".

if I display the metadata attributes with

mdls < filename >

I can see the the Content Type is different:

file 1 shows:

...
kMDItemContentType                  = "public.unix-executable"
...

file 2 shows:

...
kMDItemContentType                  = "com.apple.traditional-mac-plain-text" 
...

How can I set the kMDItemContentType of file 2 also to "public.unix-executable"? Is there a command line to to change it?

1

Explicitly set it within the file itself.

Right click (or option + click) the file > Open With > Other... > TextEdit.

Alternatively, you can use a text editor such as nano or vi within Terminal.

Set the attribute below the shebang line

#! /bin/bash

kMDItemContentType = "public.unix-executable" 

#Rest of your shell script

I just tested this on a script in my bin:

njboot$ mdls /Users/njboot/bin/jpgrm 
kMDItemContentCreationDate     = 2014-06-10 06:06:53 +0000
kMDItemContentModificationDate = 2014-06-11 19:58:23 +0000
kMDItemContentType             = "public.unix-executable"
kMDItemContentTypeTree         = (
    "public.unix-executable",
    "public.data",
    "public.item",
    "public.executable"
)
  • How can I edit meta attributes with nano or text edit? If I open the file I only see the file content, not the attributes ... where is the trick? – markus Jun 13 '14 at 13:20
  • @markus what type of file is this? i literally meant add it as text within the file under the presumption that it's an executable shell script. don't use nano. just use textedit. remove the executable property before opening it chmod -x /path/to/file then within the file itself add as text in a newline (below the shebang #! /bin/whatever) kMDItemContentType = "public.unix-executable" ...once done, save changes and make it executable again chmod +x /path/to/file – njboot Jun 13 '14 at 19:59
  • It is a small shell script to connect to a server via ssh, but is has no extension. Just adding #! /bin/bash changed the kMDItemContentType after saving. – markus Jun 18 '14 at 11:25
  • The funny thing is that even if I open the file again and remove "#! /bin/bash", the kMDItemContentType keeps "public.unix-executable" in the metadata attributes. – markus Jun 18 '14 at 11:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .