setfileattr

Sets attributes of a file or directory.

setfileattr <filename> <attributes>

Parameters

string <filename>
The file name or directory name
integer <attributes>
A user can specify an attribute value combined from the following (the same values as on Windows). Other values are ignored.
Value Meaning
$1 Read-only (removes the write permission)
$2 Hidden file or directory (the Finder hidden flag)

Return Value

System variable <result>
When the command fails, 0 is stored.
When the command succeeds, 1 is stored.

Example

; add readonly attribute
file = '/Users/user/test.txt'
getfileattr file
attr = result | $1 ; keep current attributes
setfileattr file attr

See also