OK I’m probably expecting too much but this is so close!! I have my Definitive Guide to Applescript on order so I can learn from the beginning instead of trying this mad script straight away. But here is where I am.
This script does everything I need it to, with only two problems.
-
It repeats the ‘add _LR’ command, I thought it would run through the script first and move the file before adding it again. So if I put one file in I get filename_LR_LR.pdf. If I add more files I can get _LR repeated tens of times.
-
When I get the script to ‘set theServer’ according to the ‘chain’ it only chooses the chain from the first file it sees. If I have two files for different chains they end up in the same chain together. But if all the files are from one chain they will go to the correct location.
(*Add _LR to filename*)
on adding folder items to this_folder after receiving these_items
set the the_new_text to "_LR"
repeat with oneItem in these_items
set {name:Nm, name extension:Ex} to (info for oneItem)
if Ex is missing value then set Ex to ""
if Ex is not "" then
set Nm to text 1 thru ((count Nm) - (count Ex) - 1) of Nm
set Ex to "." & Ex
end if
tell application "Finder"
set name of oneItem to (Nm & the_new_text & Ex)
end tell
end repeat
(*Set chain*)
set {tid, text item delimiters} to {text item delimiters, "_"}
tell application "Finder"
repeat with oneItem in these_items
set fileName to name of oneItem
-- fileName is now equal to 06_005_05C_904746_RP_SPG_LR.jpg
set {jc1, jc2, wc} to text items of fileName
-- jc1 = 06
-- jc2 = 005
-- wc = 05C
set chain to text 3 thru -1 of wc
-- chain = C
-- If the Week Chain had been 51PDC then chain would be equal to PDC
try
if chain = "C" then
set theServer to "/Users/olisaund/Desktop/Currys/Weeks/"
else if chain = "PCW" then
set theServer to "/Users/olisaund/Desktop/PCW/Weeks/"
end if
end try
end repeat
end tell
(*Move file to correct server based on chain path*)
repeat with oneItem in these_items
set {tid, text item delimiters} to {text item delimiters, "_"}
set {theGroup, na, theWeek, na, na, na} to text items of (name of (info for oneItem))
set text item delimiters to tid
try
set command to "/bin/mv -f " & (quoted form of (POSIX path of oneItem)) & space & (quoted form of theServer) & "Week" & (text 1 thru 2 of theWeek) & "/" & theGroup & "*/" & "/" & "/"
do shell script command
on error
display dialog command
end try
end repeat
end adding folder items to
Model: MacBook 1.83GHz
Browser: Safari 525.27.1
Operating System: Mac OS X (10.5)