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

Solution 1:

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.

Solution 2:

Try giving it 0 write access with:

sudo chmod 444 FILE_NAME

That will prevent the file from being written to. After you've done that, use the sudo chflags hidden command to hide them.