I was unable to compile your script on my machine.
The problem was the very first property defining an alias which doesn’(t exists on my machine.
So I made some small changes to be able to compile.
Here is the edited version :
property csvAlias : ((path to desktop as text) & "SourceFiles:ean2sku.csv") --path to your csv-File as string to be able to compile on my machine
property csvDelimiter : "," --delimiter used by your csv-File
tell application "Finder"
set this_folder to folder "HotFolder" as alias
set itemList to every file in this_folder
end tell
try
set TID to AppleScript's text item delimiters
repeat with i from 1 to count of itemList
set newFile to item i of itemList
tell application "System Events" to set {fSuffix, fName} to {(name extension of disk item (newFile as text)), (displayed name of disk item (newFile as text))}
if fSuffix is not "" then set fSuffix to "." & fSuffix
set fName to my stripSuffix(fSuffix, fName)
set tmpName to (text 1 thru 13 of fName)
set csvText to read file csvAlias (* to be able to compile on my machine *)
if csvText contains tmpName then
set AppleScript's text item delimiters to tmpName & csvDelimiter
set newListName to (text 1 thru -1 of (paragraph 1 of (text item 2 of csvText)))
if (count of fName) is greater than 13 then
set newName to newListName & (text 14 thru -1 of fName) & fSuffix
else
set newName to newListName & fSuffix
end if
my renameFile(this_folder, fName & fSuffix, newName)
end if
end repeat
set AppleScript's text item delimiters to TID
on error
display dialog "Could not rename: " & fName giving up after 3
end try
on stripSuffix(fSuffix, fName)
if fName contains fSuffix then
set AppleScript's text item delimiters to fSuffix
return (text item 1 of fName)
end if
end stripSuffix
on renameFile(this_folder, origName, newName)
set sourcePath to quoted form of POSIX path of ((this_folder as text) & origName)
set targetPath to quoted form of POSIX path of ((this_folder as text) & newName)
do shell script "mv -f " & sourcePath & space & targetPath
end renameFile
-- This areas then moves the files to the relevant folders
property type_list : {"TIFF", "JPEG", "PNGf", "PICT"}
property extension_list : {"tif", "tiff", "jpg", "jpeg", "png", "pict", "psd"}
set tFolder to ((path to desktop as text) & "HotFolder") as string
tell application "Finder"
repeat with tFile in (get document files of folder tFolder whose name extension is in extension_list and (name does not start with "50" and name does not start with "MJC"))
set nLayers to my getNumOfLayers(tFile as string)
if nLayers < 5 then
move tFile to the folder ((path to pictures folder from user domain as text) & "HotFolder2do") -- move to subFolder A
else
move tFile to the folder ((path to pictures folder from user domain as text) & "HotFolderDone")
end if
end repeat
end tell
on getNumOfLayers(f)
((do shell script "/usr/bin/mdls -name kMDItemLayerNames " & (quoted form of POSIX path of f) & " | /usr/bin/wc -l ") as integer) - 2
end getNumOfLayers
May you try the script with a modified structure ?
property csvAlias : ((path to desktop as text) & "SourceFiles:ean2sku.csv") --path to your csv-File as string to be able to compile on my machine
property csvDelimiter : "," --delimiter used by your csv-File
-- This areas then moves the files to the relevant folders
property type_list : {"TIFF", "JPEG", "PNGf", "PICT"}
property extension_list : {"tif", "tiff", "jpg", "jpeg", "png", "pict", "psd"}
tell application "Finder"
set this_folder to folder "HotFolder" as alias
set itemList to every file in this_folder
end tell
try
set TID to AppleScript's text item delimiters
repeat with i from 1 to count of itemList
set newFile to item i of itemList
tell application "System Events" to set {fSuffix, fName} to {(name extension of disk item (newFile as text)), (displayed name of disk item (newFile as text))}
if fSuffix is not "" then set fSuffix to "." & fSuffix
set fName to my stripSuffix(fSuffix, fName)
set tmpName to (text 1 thru 13 of fName)
set csvText to read file csvAlias (* to be able to compile on my machine *)
if csvText contains tmpName then
set AppleScript's text item delimiters to tmpName & csvDelimiter
set newListName to (text 1 thru -1 of (paragraph 1 of (text item 2 of csvText)))
if (count of fName) is greater than 13 then
set newName to newListName & (text 14 thru -1 of fName) & fSuffix
else
set newName to newListName & fSuffix
end if
my renameFile(this_folder, fName & fSuffix, newName)
end if
end repeat
set AppleScript's text item delimiters to TID
on error
display dialog "Could not rename: " & fName giving up after 3
end try
set tFolder to ((path to desktop as text) & "HotFolder") as string
tell application "Finder"
repeat with tFile in (get document files of folder tFolder whose name extension is in extension_list and (name does not start with "50" and name does not start with "MJC"))
set nLayers to my getNumOfLayers(tFile as string)
if nLayers < 5 then
move tFile to the folder ((path to pictures folder from user domain as text) & "HotFolder2do") -- move to subFolder A
else
move tFile to the folder ((path to pictures folder from user domain as text) & "HotFolderDone")
end if
end repeat
end tell
-- Now the handlers.
(*
I edited this one *)
on stripSuffix(fSuffix, fName)
if fName contains fSuffix then
set oTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to fSuffix
set prefx to (text item 1 of fName)
set AppleScript's text item delimiters to oTIDs
return prefx
end if
end stripSuffix
on renameFile(this_folder, origName, newName)
set sourcePath to quoted form of POSIX path of ((this_folder as text) & origName)
set targetPath to quoted form of POSIX path of ((this_folder as text) & newName)
do shell script "mv -f " & sourcePath & space & targetPath
end renameFile
on getNumOfLayers(f)
((do shell script "/usr/bin/mdls -name kMDItemLayerNames " & (quoted form of POSIX path of f) & " | /usr/bin/wc -l ") as integer) - 2
end getNumOfLayers
Yvan KOENIG (VALLAURIS, France) mercredi 29 février 2012 21:28:13