macOS – How to Recursively Change File Type

applescriptcommand linemacosterminal

I have folders, containing files and folders.
Among these files, some have extension, some have no extension.

I noticed that a file without extension can have a type (probably stored in some kind of metadata)

Example of a TextEdit file without extension :

enter image description here

Example of a Document Sublime Text file without extension :

enter image description here

What I want is recursively exploring folders and changing the type of files without extension.

I am not talking about setting a default app for all files without extension.

I am talking about changing each file individually (metadata), to set there type to "Document Sublime Text"

I am looking for something like that :

find ./ -depth <file has no extension> -exec <set file type = Document Sublime Text>

Or an AppleScript !

Best Answer

I did it with xattr ! My final script is :

find FOLDER -type f ! -name "*.*" -print0 | xargs -0 xattr -wx com.apple.LaunchServices.OpenWith \
"`xattr -px com.apple.LaunchServices.OpenWith FILEWITHGOODTYPE`"

Replace FOLDER by your folder (containing files without extension) (drag and drop)

Replace FILEWITHGOODTYPE by a file which has the expected type (drag and drop)


I found what I was looking for here :

https://stackoverflow.com/q/4833052/4135158