Я сделал удар в темноте и подумал, что, возможно, проблема в том, что размер файла, который был создан, был 0 КБ. Я решил добавить обработчик с помощью команды write to file
и добавил в файл один пробел в качестве символа. Это сделало файл размером 1 байт, а затем установил индекс метки. Я внес несколько незначительных изменений в ваш исходный код для моих целей, но вот изменения, которые я сделал, и мою версию кода.
local unset, orange, red, yellow, blue, purple, green, grey
set {unset, orange, red, yellow, blue, purple, green, grey} to {0, 1, 2, 3, 4, 5, 6, 7}
set tmplFileName to "__ReadMe"
set nameExtension to ".txt"
set labelTag to red
tell application "Finder"
set currentPath to insertion location
set txtfilename to tmplFileName & nameExtension
set txtFile to make new file at insertion location as alias with properties {name:txtfilename, name extension:nameExtension}
my writeToTheFile(txtFile as alias)
set the label index of (txtFile as alias) to labelTag
open txtFile
end tell
on writeToTheFile(txtFile as alias)
set theFile to txtFile as alias
set theText to " "
try
set writeToFile to open for access theFile with write permission
write theText to writeToFile as text starting at eof
close access theFile
on error errMsg number errNum
try
close access theFile
end try
end try
end writeToTheFile