tell application "Finder"
set chemin to choose folder with prompt "Sélectionnez le dossier contenant les fichiers à renommer"
set tous to every file of entire contents of chemin
set nb to count tous
repeat with i from 1 to nb
make new folder at desktop with properties {name:"Temp"}
set ledossiertemp to ((path to desktop folder as text) & "Temp:") as alias
set lefichiertexte to ((path to desktop folder as text) & "Temp:Letexte.txt")
set lepdf to item i of tous
set sauv to AppleScript's text item delimiters --sauvegarder la variable delimiteur
set AppleScript's text item delimiters to {"."} --récupère la partie avant le dernier "."
set elements to text items of (name of lepdf as string) --nom --ou of (name of a as string)
set nomcourt to (items 1 thru -2 of elements) as string
set AppleScript's text item delimiters to sauv --restaurer la variable delimiteur
duplicate lepdf to ledossiertemp
tell application "PDFenTEXTE"
launch
activate
end tell
delay 2
set sauv to AppleScript's text item delimiters
set lefich to lefichiertexte
set lefichierUnix to quoted form of POSIX path of lefichiertexte
do shell script "textutil -convert txt -encoding UTF-8 " & lefichierUnix
set letexte to read file lefich
set ajout to ""
set AppleScript's text item delimiters to "Contrat n° : "
set nb to count text item of letexte
repeat with i from 2 to nb
set suite to text item i of letexte
set lessept to text 1 thru 7 of suite as text
set ajout to ajout & "-" & lessept
end repeat
set AppleScript's text item delimiters to sauv
set name of lepdf to nomcourt & ajout & ".pdf"
do shell script "rm -r " & POSIX path of ledossiertemp
end repeat
end tell
tell application "Finder"
activate
(display dialog ("waouou ... Ca y est c'est fait !") buttons {"Salut !"})
end tell
tell application "Finder"
set chemin to choose folder with prompt "Sélectionnez le dossier contenant les fichiers à renommer"
set tous to every file of entire contents of chemin
set nb to count tous
repeat with i from 1 to nb
make new folder at desktop with properties {name:"Temp"}
set ledossiertemp to ((path to desktop folder as text) & "Temp:") as alias
set lefichiertexte to ((path to desktop folder as text) & "Temp:Letexte.txt")
set lepdf to item i of tous
set sauv to AppleScript's text item delimiters --sauvegarder la variable delimiteur
set AppleScript's text item delimiters to {"."} --récupère la partie avant le dernier "."
set elements to text items of (name of lepdf as string) --nom --ou of (name of a as string)
set nomcourt to (items 1 thru -2 of elements) as string
set AppleScript's text item delimiters to sauv --restaurer la variable delimiteur
duplicate lepdf to ledossiertemp
tell application "PDFenTEXTE"
launch
activate
end tell
delay 2
set sauv to AppleScript's text item delimiters
set lefich to lefichiertexte
set lefichierUnix to quoted form of POSIX path of lefichiertexte
do shell script "textutil -convert txt -encoding UTF-8 " & lefichierUnix
set lefich to lefichiertexte as alias
set letexte to read file lefich
set ajout to ""
set AppleScript's text item delimiters to "Contrat n° : "
set nb to count text item of letexte
display dialog (nb - 1)
repeat with i from 2 to nb
set suite to text item i of letexte
set lessept to text 1 thru 7 of suite as text
set ajout to ajout & "-" & lessept
end repeat
set AppleScript's text item delimiters to sauv
set name of lepdf to nomcourt & ajout & ".pdf"
do shell script "rm -r " & POSIX path of ledossiertemp
end repeat
end tell
tell application "Finder"
activate
(display dialog ("waouou ... Ca y est c'est fait !") buttons {"Salut !"})
end tell
tell application "Finder"
set chemin to choose folder with prompt "Sélectionnez le dossier contenant les fichiers à renommer"
set tous to every file of entire contents of chemin
set nb to count tous
repeat with i from 1 to nb
make new folder at desktop with properties {name:"Temp"}
set ledossiertemp to ((path to desktop folder as text) & "Temp:") as alias
set lefichiertexte to ((path to desktop folder as text) & "Temp:Letexte.txt")
set lepdf to item i of tous
set sauv to AppleScript's text item delimiters --sauvegarder la variable delimiteur
set AppleScript's text item delimiters to {"."} --récupère la partie avant le dernier "."
set elements to text items of (name of lepdf as string) --nom --ou of (name of a as string)
set nomcourt to (items 1 thru -2 of elements) as string
set AppleScript's text item delimiters to sauv --restaurer la variable delimiteur
duplicate lepdf to ledossiertemp
tell application "PDFenTEXTE"
launch
activate
end tell
delay 2
set sauv to AppleScript's text item delimiters
set lefich to lefichiertexte
set ajout to ""
set AppleScript's text item delimiters to "Contrat n° : "
-- essai pour voir si trouve format UTF-8
set lefich to lefichiertexte as alias
set letexte to read file lefich
set nb to count text item of letexte
if nb = 1 then
set lefichierUnix to quoted form of POSIX path of lefichiertexte
do shell script "textutil -convert txt -encoding UTF-8 " & lefichierUnix
set lefich to lefichiertexte as alias
set letexte to read file lefich
set AppleScript's text item delimiters to "Contrat n° : "
set nb to count text item of letexte
end if
repeat with i from 2 to nb
set suite to text item i of letexte
set lessept to text 1 thru 7 of suite as text
set ajout to ajout & "-" & lessept
end repeat
set AppleScript's text item delimiters to sauv
set name of lepdf to nomcourt & ajout & ".pdf"
do shell script "rm -r " & POSIX path of ledossiertemp
end repeat
end tell
tell application "Finder"
activate
(display dialog ("waouou ... Ca y est c'est fait !") buttons {"Salut !"})
end tell
tell application "Finder"
set chemin to choose folder with prompt "Sélectionnez le dossier contenant les fichiers à renommer"
set tous to every file of entire contents of chemin
set nb to count tous
repeat with i from 1 to nb
make new folder at desktop with properties {name:"Temp"}
set ledossiertemp to ((path to desktop folder as text) & "Temp:") as alias
set lefichiertexte to ((path to desktop folder as text) & "Temp:Letexte.txt")
set lepdf to item i of tous
set sauv to AppleScript's text item delimiters --sauvegarder la variable delimiteur
set AppleScript's text item delimiters to {"."} --récupère la partie avant le dernier "."
set elements to text items of (name of lepdf as string) --nom --ou of (name of a as string)
set nomcourt to (items 1 thru -2 of elements) as string
set AppleScript's text item delimiters to sauv --restaurer la variable delimiteur
duplicate lepdf to ledossiertemp
tell application "PDFenTEXTE"
launch
activate
end tell
delay 2
display dialog "stop"
set sauv to AppleScript's text item delimiters
set lefich to lefichiertexte
set ajout to ""
set AppleScript's text item delimiters to "Contrat n"
-- essai pour voir si trouve format UTF-8
set lefich to lefichiertexte as alias
set letexte to read file lefich
set nb to count text item of letexte
if nb = 1 then
set lefichierUnix to quoted form of POSIX path of lefichiertexte
do shell script "textutil -convert txt -encoding UTF-8 " & lefichierUnix
set lefich to lefichiertexte as alias
set letexte to read file lefich
set AppleScript's text item delimiters to "Contrat n"
set nb to count text item of letexte
end if
repeat with i from 2 to nb
set suite to text item i of letexte
set lessept to text 5 thru 11 of suite as text
set ajout to ajout & "-" & lessept
end repeat
set AppleScript's text item delimiters to sauv
set name of lepdf to nomcourt & ajout & ".pdf"
do shell script "rm -r " & POSIX path of ledossiertemp
end repeat
end tell
tell application "Finder"
activate
(display dialog ("waouou ... Ca y est c'est fait !") buttons {"Salut !"})
end tell
Curieux, bref pas grave !C'est bon, mais il manque un chiffre (le dernier) à chaque numéro de contrat.
set lessept to text 5 thru 11 of suite as text
set lessept to text 5 thru 12 of suite as text
tell application "Finder"
set chemin to choose folder with prompt "Sélectionnez le dossier contenant les fichiers à renommer"
set tous to every file of entire contents of chemin
set nb to count tous
repeat with i from 1 to nb
make new folder at desktop with properties {name:"Temp"}
set ledossiertemp to ((path to desktop folder as text) & "Temp:") as alias
set lefichiertexte to ((path to desktop folder as text) & "Temp:Letexte.txt")
set lepdf to item i of tous
set sauv to AppleScript's text item delimiters --sauvegarder la variable delimiteur
set AppleScript's text item delimiters to {"."} --récupère la partie avant le dernier "."
set elements to text items of (name of lepdf as string) --nom --ou of (name of a as string)
set nomcourt to (items 1 thru -2 of elements) as string
set AppleScript's text item delimiters to sauv --restaurer la variable delimiteur
duplicate lepdf to ledossiertemp
tell application "PDFenTEXTE"
launch
activate
end tell
delay 2
set sauv to AppleScript's text item delimiters
set lefich to lefichiertexte
set ajout to ""
set AppleScript's text item delimiters to "Contrat n"
-- essai pour voir si trouve le mot (format UTF-8)
set lefich to lefichiertexte as alias
set letexte to read file lefich
set nb to count text item of letexte
--si pas trouvé peut être utf 16 alors convert et re-essai ( attention certain caractères pas reconnu "°")
if nb = 1 then
set lefichierUnix to quoted form of POSIX path of lefichiertexte
do shell script "textutil -convert txt -encoding UTF-8 " & lefichierUnix
set lefich to lefichiertexte as alias
set letexte to read file lefich
set AppleScript's text item delimiters to "Contrat n"
set nb to count text item of letexte
end if
repeat with i from 2 to nb
set suite to text item i of letexte
set lessept to text 5 thru 12 of suite as text
set ajout to ajout & "-" & lessept
end repeat
set AppleScript's text item delimiters to sauv
set name of lepdf to nomcourt & ajout & ".pdf"
do shell script "rm -r " & POSIX path of ledossiertemp
end repeat
end tell
tell application "Finder"
activate
(display dialog ("waouou ... Ca y est c'est fait !") buttons {"Salut !"})
end tell