OK !
essai ce script:
essai ce script:
Bloc de code:
tell application "Finder"
set lechemin to choose folder with prompt "Sélectionnez le Dossier principal à traiter ?"
display dialog "Entrer le chiffre à ajouter à l'ISBN :" default answer ""
set lechiffre to text returned of result
set lecheminfichierindd to choose file with prompt "Sélectionnez le gabarits Indesign à copier ?"
set lecheminfichiercl to choose file with prompt "Sélectionnez le CL à copier ?"
display dialog "Entrer le numero de la table SN :" default answer ""
set ntablesn to text returned of result
display dialog "Entrer le numero d'édition :" default answer ""
set nedition to text returned of result
set ledossier to name of lechemin
set isbn to characters 1 thru 3 of ledossier & "-" & character 4 of ledossier & "-" & characters 5 thru 7 of ledossier & "-" & characters 8 thru 12 of ledossier & "-" & lechiffre as text
set lenomdossier to characters 13 thru -4 of ledossier as text
repeat with i from 1 to count lenomdossier
if item i of lenomdossier is " " then
set lenomdossier to items 1 thru (i - 1) of lenomdossier & "-" & items (i + 1) thru -1 of lenomdossier
end if
end repeat
set lenomdossier to lenomdossier as text
set lenomdossier to my remplace(lenomdossier)
set newnomledossier to isbn & (lenomdossier as text)
set sauv to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}
set chem to lechemin as string
set chemin to text items 1 thru -3 of chem as string
set newchemin to chemin & ":" & newnomledossier
set AppleScript's text item delimiters to sauv
display dialog newnomledossier
make new folder at chemin with properties {name:newnomledossier}
make new folder at newchemin with properties {name:newnomledossier & "_fl1"}
make new folder at newchemin with properties {name:newnomledossier & "_fl2"}
make new folder at newchemin with properties {name:isbn & "_" & ntablesn & "_" & nedition & "_fl3"}
make new folder at newchemin & ":" & newnomledossier & "_fl1" with properties {name:"corps-de-livre"}
make new folder at newchemin & ":" & newnomledossier & "_fl1" with properties {name:"couverture"}
make new folder at newchemin & ":" & newnomledossier & "_fl2" with properties {name:"corps-de-livre"}
make new folder at newchemin & ":" & newnomledossier & "_fl2" with properties {name:"couverture"}
-- duplique les dossiers
set lesdossiers to folders of lechemin
set nb to count lesdossiers
repeat with i from 1 to nb
duplicate item i of lesdossiers to newchemin & ":" & newnomledossier & "_fl1:couverture"
end repeat
repeat with i from 1 to nb
duplicate item i of lesdossiers to newchemin & ":" & newnomledossier & "_fl2:couverture"
end repeat
--duplique les fichiers
set lesfichiers to files of lechemin
set nb to count lesfichiers
repeat with i from 1 to nb
duplicate item i of lesfichiers to newchemin & ":" & newnomledossier & "_fl1:couverture"
end repeat
repeat with i from 1 to nb
duplicate item i of lesfichiers to newchemin & ":" & newnomledossier & "_fl2:couverture"
end repeat
-- fin duplique
--duplique le fichier indd
duplicate lecheminfichierindd to newchemin & ":" & newnomledossier & "_fl2:couverture"
set lefichierindd to name of lecheminfichierindd
set nomindd to isbn & "_" & ntablesn & "+2mm_cv_400.indd"
set lenewcheminfichierindd to newchemin & ":" & newnomledossier & "_fl2:couverture:" & lefichierindd
set lenewcheminfichierindd to lenewcheminfichierindd as alias
set name of lenewcheminfichierindd to nomindd
--duplique le fichier CL
duplicate lecheminfichiercl to newchemin & ":" & newnomledossier & "_fl1:corps-de-livre"
duplicate lecheminfichiercl to newchemin & ":" & newnomledossier & "_fl2:corps-de-livre"
--duplique le fichier datamatrix
set ledatamatrix to "Macintosh HD:Utilisateurs:Socprest:Travaux en cours:NOUVEAUTES:GABARITS:DATAMATRIX:DATAMATRIX_.pdf"
duplicate ledatamatrix to newchemin
set lenewchemin to newchemin as string
set lenewchemin to lenewchemin & ":Datamatrix_.pdf"
set lenewchemin to lenewchemin as alias
set name of lenewchemin to ("Datamatrix_" & ntablesn & ".pdf")
--fin duplique datamatrix
--efface fichier original
set ledossier to quoted form of POSIX path of lechemin
do shell script "rm -rf " & ledossier
end tell
on remplace(mavar)
set aremplacer to {39, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90}
set par to {45, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122}
set nbar to count aremplacer
set new to mavar
-- remplace les caractères de la liste
set nb to count characters in new
set mavar to new
repeat with i from 1 to nb
set a to character i in mavar
set lavaleur to ASCII number a
repeat with j from 1 to nbar
if item j of aremplacer is lavaleur then
set newcar to ASCII character (item j of par)
if i = 1 then
set new to newcar & (text 2 thru nb of new)
set avant to ""
else
set avant to text 1 thru (i - 1) of new
end if
if i = nb then
set new to avant & newcar
else
set new to avant & newcar & text nb thru -(nb - i) of mavar
end if
end if
end repeat
end repeat
set mavar to new
end remplace