This is a simple script that just changes the file extension of all the files in the selected folder from .jpg to .tif. and it successfully changes the file extension, the problem is when i run a little error checking if/then statement to make sure the extension is a .tif. i get an error that says "Finder got an error: Cant get document file" it then shows the file name and path of the current file. if anyone could help me out with this that would be great. and if the syntax isn't correct, feel free to point that out.
on writeErrors(errorData, logLocation, append_data) -->SubRoutine for Log File
try
set the logLocation to the logLocation as text
set the open_target_file to ¬
open for access file logLocation with write permission
if append_data is false then ¬
set eof of the open_target_file to 0
write errorData to the open_target_file starting at eof
close access the open_target_file
return true
on error
try
close access file logLocation
end try
return false
end try
end writeErrors
set this_folder to choose folder with prompt "Choose jpg Folder to convert into tif's"
set pFiles to {} --problem files
set cConverted to 0 --count converted
tell application "Finder"
set filelist to every file of this_folder
set tCount to the number of items in filelist as Unicode text
end tell
repeat with thisFile in filelist
with timeout of 43000 seconds
tell application "Finder"
try
if name extension of thisFile is "jpg" then
set name extension of thisFile to "tif"
end if
on error
set pFiles to (pFiles & {thisFile})
set label index of thisFile to 2
end try --if i take out the next 4 lines, the script runs fine
set nExten to name extension of thisFile --this is where i get the error, "can't get document info"
if nExten is "tif" then
set cConverted to (cConverted + 1)
end if
end tell
end timeout
end repeat
set errorData to pFiles as text
set logLocation to (path to desktop as string) & "jpg-tif_errors.txt"
my writeErrors(errorData, logLocation, true)
display dialog "All done!" & " Total: " & tCount & " Converted: " & cConverted buttons {"OK"} default button 1 with icon 1 giving up after 10
on writeErrors(errorData, logLocation, append_data) -->SubRoutine for Log File
try
set the logLocation to the logLocation as text
set the open_target_file to ¬
open for access file logLocation with write permission
if append_data is false then ¬
set eof of the open_target_file to 0
write errorData to the open_target_file starting at eof
close access the open_target_file
return true
on error
try
close access file logLocation
end try
return false
end try
end writeErrors
set this_folder to choose folder with prompt "Choose jpg Folder to convert into tif's"
set pFiles to {} --problem files
set cConverted to 0 --count converted
tell application "Finder"
set filelist to every file of this_folder
set tCount to the number of items in filelist as Unicode text
end tell
repeat with thisFile in filelist
with timeout of 43000 seconds
tell application "Finder"
try
if name extension of thisFile is "jpg" then
set name extension of thisFile to "tif"
end if
on error
set pFiles to (pFiles & {thisFile})
set label index of thisFile to 2
end try --if i take out the next 4 lines, the script runs fine
set nExten to name extension of thisFile --this is where i get the error, "can't get document info"
if nExten is "tif" then
set cConverted to (cConverted + 1)
end if
end tell
end timeout
end repeat
set errorData to pFiles as text
set logLocation to (path to desktop as string) & "jpg-tif_errors.txt"
my writeErrors(errorData, logLocation, true)
display dialog "All done!" & " Total: " & tCount & " Converted: " & cConverted buttons {"OK"} default button 1 with icon 1 giving up after 10