MacOS – How to keep a file hidden in Finder, but readable, writable and visible to an app

findermacospermissionterminal

An otherwise great app I'm using, annoys me as every time I start it, it writes to 2 files in the root of my user account which are clearly visible. Now, I have used the terminal command sudo chflags hidden with the name of the files to hide them, which does work, but nonetheless, when I launch the app again, it makes those once hidden files visible again!

The files content stays the same, so either its being re-written, or its being made visible again once the app is finished with them after boot, and whatever way it saves, the 'hidden' status of the files is being ignored or changed due to write permissions used by the app (I'm guessing).

Is there any way to ensure that this app can find these files and do whatever writes and saves it has to, but I can still keep them invisible in Finder? As in keep the files hidden to my view but readable and writable to the app? Is a combo chown / chmod command needed alongside a Finder preference setting?

Best Answer

Set an immutable flag on file(s) to prevent changes*:

sudo chflags hidden,uchg /path/to/file

What's an immutable flag?

"Immutable flags, also known as immutable bits, are file system attributes that, when enabled, prohibit changes to files or folders (objects), i.e. lock them. Enabled, immutable flags supersede permissions: you cannot modify an object whose immutable flags have been enabled despite having Read & Write permissions on that object."

Note*: This will ensure that the file remains hidden, but may prevent the application from running properly if RW access is needed. This is the tradeoff. That being said, to unset the flag, you would run:

sudo chflags nouchg /path/to/file

If this is the case, I advise that you contact the developer of the application since it need not automatically make a hidden file visible in order to be able to RW to that file. That's a bug in the application itself, period.