Version légèrement modifiée.
J'ai changé à peu près tous les noms de variables espérant que ce serait plus facile à suivre.
[script]
set fichierOriginal to ((path to desktop as string) & "abcd.numbers") as alias --> alias "SSD 1000:Users:**********:Desktop:abcd.numbers"
my openThat(fichierOriginal)
on openThat(fichierOriginal) -- vérification de la nature du paramètre
if class of fichierOriginal is list then set fichierOriginal to first item of fichierOriginal
tell application "Finder"
set originalName to name of fichierOriginal --> "abcd.numbers"
set cheminOriginal to fichierOriginal as string --> "SSD 1000:Users:**********:Desktop:abcd.numbers"
set lExtension to name extension of fichierOriginal --> "numbers"
set nomcourt to text 1 thru ((length of originalName) - (1 + (length of lExtension))) of originalName
log result --> "abcd"
set dossierDuDocument to folder of fichierOriginal as alias --> alias "SSD 1000:Users:**********:Desktop:"
set nomDuDossier to name of dossierDuDocument --> "Desktop"
end tell
tell application "Numbers" --"Microsoft Excel"
activate
open fichierOriginal -- fichierOriginal est un alias
tell document 1 to tell sheet 1 to tell table 1 -- requis par "Numbers"
set theDate to (value of cell "H2") as date -- retourne une date Applescript conforme aux réglages système
set theYear to year of theDate -- nombre de 2 ou 4 chiffres
if theYear < 100 then set theYear to theYear + 2000 -- suppose que la date relève du XXIème siècle
set theYear to theYear as string
set theMonth to text 2 thru 3 of ((100 + (month of theDate as number)) as string) -- on aura toujours deux chiffres
set theDay to text 2 thru 3 of ((100 + (day of theDate)) as string) -- on aura toujours deux chiffres
set dateISO to theYear & "-" & theMonth & "-" & theDay -- crée une chaîne, inutile de forcer cette nature
log dateISO --> (*2021-04-10*)
set nouveauNom to nomDuDossier & "-" & dateISO & "." & lExtension
log nouveauNom --> (*Desktop-2021-04-10.numbers*)
set cheminDuDossier to dossierDuDocument as text
log cheminDuDossier --> (*SSD 1000:Users:**********:Desktop:*)
set nouveauChemin to cheminDuDossier & nouveauNom
log nouveauChemin --> (*SSD 1000:Users:**********:Desktop:Desktop-2021-04-10.numbers*)
set knt to 0
repeat -- 5 times durant les tests
tell application "Finder" to set maybe to exists file nouveauChemin
if maybe then
-- traitement si fichier présent
--set result to "Présent"
set knt to knt + 1
set nouveauNom to nomDuDossier & "-" & dateISO & "-" & knt & "." & lExtension
log nouveauNom --> (*Desktop-2021-04-10-1.numbers*)
set nouveauChemin to cheminDuDossier & nouveauNom
log nouveauChemin --> (*SSD 1000:Users:**********:Desktop:Desktop-2021-04-10-1.numbers*)
set value of cell "B7" to nouveauChemin --pour test
else
-- traitement si fichier absent
--set result to "Absent"
exit repeat
end if
end repeat
tell application "Finder" to set name of fichierOriginal to nouveauNom
end tell -- requis par "Numbers"
end tell
end openThat
[/script]
Yvan KOENIG (VALLAURIS, France) lundi 10 mai 2021 12:17:07
_______________________________________________
Applescript_fr mailing list
Applescript_fr@???
http://listes.patpro.net/mailman/listinfo/applescript_fr