Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

renommer un fichier avec AppleScript ?

1 réponse
Avatar
Pierre
Bjr,

Avec AppleScript j'ai besoin de renommer un fichier de la façon suivante
: Le nouveau nom d'un fichier doit être équivalent à l'ancien nom auquel
on ajoute la date et l'heure.
Exemple :
Nom initial : toto
Nom final : toto_01_06_05_10_32_03
(car nous sommes le 1/06/05 et qu'il est 10:32:03

Comment faire cela ?

1 réponse

Avatar
Martin
Peut-être y-a-t-il plus simple mais ceci marche :

on getTheDate()
set today to (current date)
set suffix to "_"

set prefix to ""
if (day of today) < 10 then
set prefix to "0"
end if
set suffix to (suffix & prefix & ((day of today) as string))


copy today to temp
set temp's month to January
set monthNum to (today - temp + 3944592) div 2629728
set prefix to ""
if monthNum < 10 then
set prefix to "0"
end if
set suffix to (suffix & "_" & prefix & (monthNum as string))


set suffix to (suffix & "_" & (text 3 thru 4 of (year of today as
string)))

set suffix to (suffix & "_" & ((time of (current date)) div 3600))

set suffix to (suffix & "_" & (((time of (current date)) mod 3600) div
60))

set suffix to (suffix & "_" & (((time of (current date)) mod 3600) mod
60))

return suffix
end getTheDate

set suffix to getTheDate()

tell application "Finder"
set monFichier to folder "toto" of folder "Documents" of home
set name of monFichier to ((name of monFichier) & suffix)
end tell

Explications :
1) Je définis la fonction getTheDate() qui renvoie la chaine de
caractères "_01_06_05_10_32_03" (modulo la bonne date)
2) J'appelle la fonction et je mets le résultat dans la variable
suffix
3) Je renomme le dossier "toto" du dossier Documents de mon dossier
d'utilisateur. Cette troisième partie est à adapter au script.

--
Martin.