tell application "Finder"
set source to choose folder with prompt "Sélectionnez le dossier contenant les fichiers à bordurer" as string
set epaisseur to display dialog "Entrer la valeur pour l'épaisseur du cadre blanc :" default answer "0,035"
set epaisseur to text returned of result
set ratio to display dialog "Entrer la valeur pour le ration haut bas (2 ou 3 ou 4 ou..) :" default answer "3"
set ratio to text returned of result
set Fimage to {"jpg", "jpeg", "png", "tiff", "gif", "bmp", "psd"} -- liste des extensions a traiter dans Fimage avec fonction mdls
set lesfichiers to files of source
repeat with chaque_fichier in lesfichiers -- répète avec chaque fichier du dossier en cour
tell application "Finder"
set nom to name of chaque_fichier --récupère le nom du fichier
set AppleScript's text item delimiters to {"."} -- defini le separateur
set lextension to get last text item of nom -- recupère l'extension
set lefichier to chaque_fichier as string --récupère le chemin du fichier au format chaine de caractères
if lextension is in Fimage then -- si fichier video de la liste Fimage
set lechemin to POSIX path of lefichier
set lahauteur to do shell script "/usr/local/bin/exiftool -imageHeight -s3 " & quoted form of POSIX path of lefichier
set lalargeur to do shell script "/usr/local/bin/exiftool -imageWidth -s3 " & quoted form of POSIX path of lefichier
set sauv to AppleScript's text item delimiters --sauvegarder la variable delimiteur
set AppleScript's text item delimiters to {": "}
set AppleScript's text item delimiters to sauv --restaurer la variable delimiteur
set largeur to lalargeur
set hauteur to lahauteur
if largeur > hauteur then
set cadre to round {largeur * 0.0035}
else
set cadre to round {hauteur * 0.0035}
end if
set Lcadre to (largeur + cadre) as string
set Vcadre to (hauteur + cadre) as string
set couleur to "000000"
set lacommande to "sips -p " & Vcadre & " " & Lcadre & " -s formatOptions 100 --padColor " & couleur & " -i " & quoted form of lechemin
do shell script lacommande
if largeur > hauteur then
set cadre to round {Lcadre * epaisseur}
else
set cadre to round {Vcadre * epaisseur}
end if
set Lcadre to (Lcadre + cadre) as string
set Vcadre to (Vcadre + cadre) as string
set couleur to "FFFFFF"
set lacommande to "sips -p " & Vcadre & " " & Lcadre & " -s formatOptions 100 --padColor " & couleur & " -i " & quoted form of lechemin
do shell script lacommande
if largeur > hauteur then
set cadre to round {largeur * epaisseur * ((ratio - 1) * 2)}
set Vcadre to (Vcadre + cadre) as string
else
set cadre to round {hauteur * epaisseur * ((ratio - 1) * 2)}
set Vcadre to (Vcadre + cadre) as string
end if
set recadre to cadre / 2
set couleur to "FFFFFF"
set lacommande to "sips -p " & Vcadre & " " & Lcadre & " -s formatOptions 100 --padColor " & couleur & " -i " & quoted form of lechemin
do shell script lacommande
end if
end tell
tell application "Preview"
activate
set lefichier to lefichier as alias
open lefichier
tell application "System Events" to tell application process "Preview"
tell menu bar 1 to tell menu "Édition"
tell menu item "Tout sélectionner"
click
repeat recadre times
key code 125
end repeat
end tell
end tell
tell menu bar 1 to tell menu "Outils"
tell menu item "Recadrer"
click
end tell
end tell
tell menu bar 1 to tell menu "Fichier"
tell menu item "Enregistrer"
click
end tell
end tell
key code 0 using {command down}
end tell
end tell
end repeat
end tell
tell application "Finder"
activate
(display dialog ("waouou ... Ca y est c'est fait !") buttons {"Salut !"})
end tell