Count files in OneDrive

how do I count files in my OneDrive

–not working

tell application "Finder"
	set volumeName to "OneDrive" -- CHANGE THIS to your volume's name
	set volumePath to "/Volumes/" & volumeName
	set x to count every file of disk volumeName
end tell

Check your actual OneDrive path.

For example, here it’s:

~/Library/CloudStorage/OneDrive-%user name%

macOS26.2
oneDrive 25.243.1211

It’s a bit of a tricky approach, but there are ways to get the number.

Method 1:
Check and count the records in the database that the OneDrive application is referencing.

#!/usr/bin/env osascript
#coding: utf-8
use AppleScript version "2.8"
use scripting additions

set recordSystemInfo to (system info) as record
set strUserName to (short user name of recordSystemInfo) as text

set strCmd to ("/usr/bin/sqlite3 \"/Users/" & strUserName & "/Library/Group Containers/UBF8T346G9.OneDriveStandaloneSuite/OneDrive.noindex/OneDrive.dat\" \"SELECT COUNT(*) FROM dbfs_files WHERE filetype = 0;\"") as text
set strStdOut to (do shell script strCmd) as text

return strStdOut

#include DS_Store

Method 2:
Even when a user enables full download sync, OneDrive keeps the same number of files in a way that prevents the device’s storage from breaking.
You can count those files instead.

#!/usr/bin/env osascript
#coding: utf-8
use AppleScript version "2.8"
use scripting additions

set recordSystemInfo to (system info) as record
set strUserName to (short user name of recordSystemInfo) as text

set strDirPath to ("/Users/" & strUserName & "/Library/Group Containers/UBF8T346G9.OneDriveStandaloneSuite/OneDrive.noindex/OneDrive") as text
set aliasDirPath to (POSIX file strDirPath) as alias
tell application "Finder"
	set listAliasFilePath to (every file of (entire contents of aliasDirPath)) as alias list
end tell

return (count of listAliasFilePath)

#ignore DS_Store

Hopefully this is useful to someone.