-- Set up log file
set crlf to (ASCII character 13) & (ASCII character 10)
set fp to open for access file "Macintosh HD:Users:manofwy:ScriptLogs:util_cell.txt" with write permission
-- Retrieve filename
tell application "Finder"
set filename to (name of theFile) as string
end tell
write "Filename ->" & filename & "<-" & crlf & crlf to fp
-- Striping out the year from the original name
set ptrYear to ((offset of "_" in filename) + 1 as integer)
set ptrYear2 to ptrYear + 3
set year4 to (characters ptrYear thru ptrYear2 of filename)
write "Year ->" & year4 & "<- (" & ptrYear & "," & ptrYear2 & ")" & crlf to fp
-- Striping out the month from the original name
set ptrMon to ptrYear + 4
set ptrMon2 to ptrMon + 1
set month2 to (characters ptrMon thru ptrMon2 of filename)
write "Month ->" & month2 & "<- (" & ptrMon & "," & ptrMon2 & ")" & crlf to fp
-- Put the name back together
set newName to "xx" & year4 & "-" & month2 & "_util_cell"
write "newName ->" & newName & "<-" & crlf to fp
close access fp
return {hazelExportTokens:{newFilename:newName}}
The characters in blue are the only change I made between not working and working. My log file shows the correct filename in newName after the set.
Before the log file gets blamed for opening another file in the script, I added that after it already was not working to see what was going on. I also commented it out during some tests.
It really seems to be related to starting newName with digits instead of alpha.