1

So I have a folder with many files whose count changes regularly and I need to count them using AppleScript. I had a script like this in place at first:

tell application "Finder" to return count of (every file of (choose folder))

Later, while researching, I found something like this:

tell application "Finder" to return count files of (choose folder)

However neither seems to work. I can't use System Events either since the choose folder just results in an endless run loop when used inside a System Events-tell block.

The error I get is:

"Finder got an error: Expected a reference." number -1727
2
  • System Events can also handle it (although you might want to limit the count to visible files) - just don’t use the choose folder dialog in the application tell statement (a good habit to get into). Commented Jul 29, 2021 at 14:29
  • @user3439894 Do you want to write it as an answer? Commented Jul 29, 2021 at 14:38

1 Answer 1

1

If you are looking to get just the count of files within the selected folder and not subfolders or files within subfolders, then use:

tell application "Finder" to return count files of container (choose folder)

If you want the full count of items within a folder, then use:

tell application "Finder" to return count items of entire contents of container (choose folder)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.