tell application "Finder"
set laliste to choose file with prompt "Sélectionnez le fichier liste"
set chemin to laliste as string
set votreChoix to choose folder with prompt "Sélectionnez le dossier Images"
set votreChoix to votreChoix as string
end tell
tell application "Numbers" --Ouvre le fichier dans Numbers et compte les lignes
open file chemin
tell table 1 of sheet 1 of front document --"fichierxlsx"
set lignedeb to 2
set dern to row count
repeat -- boucle si le dossier image est le même
set i to lignedeb
set lig to i as string
set lacel to "c" & lig
set ledossier to value of cell lacel as string
repeat
set i to i + 1
if i > dern then
exit repeat
end if
set lig to i as string
set lacel to "c" & lig
set ledossier2 to value of cell lacel
if ledossier2 = ledossier then
else
exit repeat
end if
end repeat
set nb to i - lignedeb
set nombre to nb as string
tell application "Finder" --recupère le nom dossier, les nom associés et la liste d'image
set ledossierim to votreChoix & ledossier
if exists ledossierim then
set liste_Fichiers to files of folder (ledossierim as alias)
set nbf to count liste_Fichiers
set nnb to nb as string
set nnbf to nbf as string
else
set lelog to open for access ((path to desktop folder as text) & "les erreurs.txt") as text with write permission
write "le dossier image " & ledossier & " n'existe pas" & return to lelog starting at eof
close access lelog
set nbf to 0
end if
end tell
if nb = nbf then
set laligne to lignedeb as string
set lefich to 1
repeat nb times
set lacellule to "a" & laligne
set lenom to value of cell lacellule as string
set lacellule to "B" & laligne
set leprenom to value of cell lacellule as string
set arenom to item lefich of liste_Fichiers
set arenom to arenom as string
tell application "Finder"
set le1 to item lefich of liste_Fichiers
set lextension to name extension of le1
set name of file arenom to lenom & "_" & leprenom & "_" & ledossier & "." & lextension
set laligne to laligne + 1
set lefich to lefich + 1
end tell
end repeat
else
-- Ecrit un fichier erreur sur le bureau si nombre d'image différent du nombre de nom dans la liste
set lelog to open for access ((path to desktop folder as text) & "les erreurs.txt") as text with write permission
write "Le fichier Excel contient " & nb & " Nom et le dossier image " & ledossier & " " & nbf & " fichiers" & return to lelog starting at eof
close access lelog
end if
set lignedeb to i
if lignedeb ≥ dern then
exit repeat
end if
end repeat
end tell
end tell
tell application "Numbers"
quit
end tell
tell application "Finder"
(display dialog ("waouou ... Ca y est c'est fait !") buttons {"Salut !"})
end tell