I thought I’d perfected my renaming script with the expert help of posters here, adding a logging routine to catch failures. Everything checks out on my local drive, but as soon as I run it on an external FireWire drive it throws the following error:
Basically, it’s getting hung up on this line:
tell application "Finder" to set name of (POSIX file foundFile as alias) to real_name
But it never had that issue on the local drive. I’ve seen posted here and elsewhere about Ignoring Permissions. Could that be the issue? I’m wracking my brains as to why this script suddenly has issues.
I should also mention that the volume of files being renamed has gone up considerably, but I’m not sure why that would cause this POSIX problem. Very frustrating, as I felt I had polished this thing off and at least moved to the next level in my meager understanding of AS.
The script, the product of guidance and past work by StefanK and CalvinFold, is below:
--
-- DECLARE PROPERTIES
--
-- debugging on?
property g_debug : true
--basic file path and names
property g_home_folder_path : "LUX_Archive2"
property g_log_file_name : "Rename_Log.txt"
set sourceFolder to (choose folder) as text
set textFile to (choose file of type "TEXT") as text
-- read in the list of names
set filenameList to paragraphs of (read file textFile)
-- in order to break out the two fields we need to play
-- with text item delimiters
set {oldDelims, text item delimiters} to {text item delimiters, tab}
set err to 0
set allFiles to count filenameList
repeat with aFile in filenameList
set {codified_name, real_name} to text items of aFile
set foundFile to do shell script "/usr/bin/find " & quoted form of POSIX path of sourceFolder & " -name " & quoted form of codified_name
if foundFile is "" then
set err to err + 1
my logMe("FILE NAME: " & codified_name as text, 0)
else
tell application "Finder" to set name of (POSIX file foundFile as alias) to real_name
end if
end repeat
set text item delimiters to oldDelims
set msg to (allFiles as text) & " files processed"
if err > 0 then set msg to return & (msg & err as text) & " files not found"
display dialog msg
-- Log Entry Generation
-- With help from StephanK and CalvinFold of MacScripter
-- http://bbs.applescript.net/viewtopic.php?pid=76607#p76607
on logMe(log_string, indent_level)
if g_debug is true then --allows turning the debugger on and off so my logMe's can be left in final version
set log_target to ("LUX_Archive2:Rename_Log.txt") as text
try
set log_file_ref to open for access file log_target with write permission
repeat indent_level times
write tab to log_file_ref starting at eof
end repeat
write ((log_string as text) & return) to log_file_ref starting at eof
close access log_file_ref
return true
on error
try
close access file log_target
end try
return false
end try
end if
end logMe