Simple example of unix command chflags

Create a folder with name countFiles in Desktop folder and make couples of empty files and one of whose need to be named document.txt

  1. First we count files with ls | wc -l
  2. Second we count files with Finder

Sometimes its useful to use chflags on targets before we tell AS to do the count.
This is only 1 approach to solve the issue if the count is not correct. And if we do
a lot of unix manipulation from a script it could be useful to know we could use chflags
for the target files.

To know more: man chflags in terminal

set thePath to (path to desktop folder as text) & "countFiles"
set posixPath to quoted form of POSIX path of thePath

-- set the chflags hidden to the target file
do shell script "chflags hidden " & posixPath & "/" & "document.txt"
set unixCount to (do shell script "cd " & posixPath & "; ls | wc -l") as integer

tell application "Finder" to set fileItems to items of folder thePath

log "Count from do shell script: " & unixCount
-- This demotrate that Finder only count visibly items or items without hidden flag
log "Tell Finder to count items: " & (count fileItems)

delay 5

-- set the chflags to default 'nohidden'
do shell script "chflags nohidden " & posixPath & "/" & "document.txt"
1 Like