AppleScript / shell script error

I've created an AppleScript to change the file creation dates for several hundred scanned images so that the dates reflect the actual date the photo was taken and not the date the image was scanned.

The script is as follows:

tell application "Finder"
set selectedFiles to (get selection)
repeat with i from 1 to count of selectedFiles
set thisFile to item i of selectedFiles
set thisName to name of thisFile
set yy to first word of thisName
set newDate to yy & "01010101.01"
do shell script "touch -t " & newDate & " " & quoted form of POSIX path of thisName
end repeat
end tell

When I run the script against one test file, I get the following:
Code Block
error "Finder got an error: touch: /1953 front of house.jpg: Read-only file system" number 1

Apparently the shell script is failing because the file is considered read only. I haven't tried it but I'm assuming the shell command would also fail from a terminal session.

The folder and file permissions are set to read/write so I can't figure out why the script is failing or develop a workaround.

Any advice would be greatly appreciated.
Answered by DTS Engineer in 665552022
Code Block
error "Finder got an error: touch: /1953 front of house.jpg: Read-only file system" number 1


You’re getting this error because you passed in the path /1953 front of house.jpg to touch. The / indicates the root directory, so it’s trying to create a file 1953 front of house.jpg at the root of your file system. Modern versions of macOS have a read-only root file system, so this is failing with error 1, aka EPERM.

but for some reason not the create date/time

The touch tool is unable to set the creation date. This is because touch has a UNIX heritage and traditional UNIX systems don’t support the concept of a creation date. There may be better ways to set the creation date but the tool I usually reach for is SetFile (see its man page).

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
UPDATE:

Modified the file path and it worked to change the modified date/time but for some reason not the create date/time. Also would not work with the -m or -a operators.

tell application "Finder"
set selectedFiles to (get selection)
repeat with i from 1 to count of selectedFiles
set thisFile to item i of selectedFiles
set thisName to name of thisFile
set yy to first word of thisName
set newDate to yy & "01010000"
do shell script "touch -t " & newDate & " /Users/usernamehere/Desktop/TempPhotos/" & quoted form of thisName
end repeat
end tell
Accepted Answer
Code Block
error "Finder got an error: touch: /1953 front of house.jpg: Read-only file system" number 1


You’re getting this error because you passed in the path /1953 front of house.jpg to touch. The / indicates the root directory, so it’s trying to create a file 1953 front of house.jpg at the root of your file system. Modern versions of macOS have a read-only root file system, so this is failing with error 1, aka EPERM.

but for some reason not the create date/time

The touch tool is unable to set the creation date. This is because touch has a UNIX heritage and traditional UNIX systems don’t support the concept of a creation date. There may be better ways to set the creation date but the tool I usually reach for is SetFile (see its man page).

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thank you for explanation. That helped me understand the issue and I’ll check out setfile

AppleScript / shell script error
 
 
Q