Camelot
Thanks for your response. I can get the same situation if I just have part of the script without the python part so no race condition.
If I run the script a newly created csv I always get the can't be imported error I can run the script over and over on the same file and same result.
if I open the file in numbers either using finder or by selecting it from file open in numbers the file opens and is imported. Sometimes I can close the file and then run the script and it works fine, If I leave the csv opened and then run the script it will open another instance of the csv file and will always work correctly.
To me it looks like there is something different between the csv importer when run from within numbers and when started from Apple Script. If I knew what the difference was I may be able to modify the csv file but I have no idea where to start. The cut down shell script and the file opening part of Apple script are below
thanks for your assistance
Ron
#!/usr/bin/env bash
DF="out-2026-02.csv"
echo "__________________________________"
set -euo pipefail
osascript /Users/roncarter/development/ha/scripts/updateenergyusages.scpt $DF
echo "=================================="
Apple Script
on run args
set fCSV to item 1 of args
log fCSV
set filenameCSV to "Macintosh HD:Users:roncarter:ha:unprocessed:" & fCSV
log filenameCSV
tell application "Numbers Creator Studio"
activate
try
set thisCSV to open filenameCSV
on error errorMessage number errorNumber
if errorNumber is not -128 then
display alert errorNumber message errorMessage
end if
end try