Output folder contents to .CSV with alphabets removed from filename
You could try the following example AppleScript code:

set src to quoted form of ¬
    (choose folder with prompt "Choose source folder where source tree is rooted at")'s POSIX path

set shellCommand to ¬
    "cd " &amp; src &amp; " &amp;&amp; echo 'Object #' &gt; \"$HOME/Desktop/names.csv\"; ls | grep -Eo '^[0-9]+' | sort -u &gt;&gt; \"$HOME/Desktop/names.csv\""

do shell script shellCommand




Note: The example AppleScript code is just that and does not contain any error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay command may be necessary between events where appropriate, e.g. delay 0.5, with the value of the delay set appropriately.