1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 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 91 92 93 94 95 96 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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978
|
on open theFiles
set theFiles to theFiles as list
display dialog "Choissez une des deux fonctions :" buttons {"Pivoter", "Convertir en JPG", "Sortir"} default button 1
set the button_pressed to the button returned of the result
if the button_pressed is "Pivoter" then
display dialog "Indiquez le sens de rotation : " buttons {"90°", "-90°", "Sortir"} default button 1
if the button returned of the result is "90°" then
set Degre to 90
else if the button returned of the result is "-90°" then
set Degre to 270
else
return
end if
repeat with aFile in theFiles
set aFile to aFile as alias
tell application "Image Events"
launch
set theImage to open aFile
rotate theImage to angle Degre
save theImage in aFile
close aFile
end tell
end repeat
else if the button_pressed is "Convertir en JPG" then
repeat with aFile in theFiles
tell application "Finder"
set fileName to the name of aFile
set filePath to aFile as string
set nbrChar to (count of characters of fileName)
set nbrChar to -nbrChar - 1
set filePath to text 1 thru nbrChar of (get filePath)
set aFile to aFile as alias
set TID to AppleScript's text item delimiters
set AppleScript's text item delimiters to "."
set theFile to text item 1 of fileName
set theExtension to text item 2 of fileName
set AppleScript's text item delimiters to ""
set AppleScript's text item delimiters to TID
if theExtension = "JPG" then
set theFile to theFile & " - 2.JPG" as text
else
set theFile to theFile & ".JPG" as text
end if
end tell
tell application "Image Events"
launch
set theImage to open aFile
tell theImage
save in filePath & theFile as JPEG
close
end tell
end tell
end repeat
else
return
end if
end open
display dialog "Que voulez-vous faire ?
- Trier des fichiers.
- Renommer des fichiers.
- Redater des fichiers." buttons {"Trier", "Renommer", "Redater"} default button 1
if the button returned of the result is "Trier" then
set tour to "on"
repeat while tour is "on"
--Sélection des dossiers out et in
set dossier_pref to (path to preferences) as string
----------------------------------
--Sélection du dossier out
set le_dossier_memorise to ""
try
set path_to_file_pref to dossier_pref & "TriPathOut" as alias
open for access path_to_file_pref with write permission
set le_dossier_memorise to read path_to_file_pref as string
close access path_to_file_pref
on error
tell application "Finder" to make new file at alias dossier_pref with properties {name:"TriPathOut", creator type:"????", file type:"pref", locked:false, busy status:false, short version:"", long version:""}
set path_to_file_pref to dossier_pref & "TriPathOut" as alias
end try
if le_dossier_memorise = "" then
display dialog "Désignez le dossier d'origine..." buttons {"Chercher", "Sortir"} default button 1
if the button returned of the result is "Chercher" then
set out_folder to (choose folder with prompt "Désigner le dossier d'origine :") as string
else
tell application "Finder" to delete dossier_pref & "TriPathOut"
return
end if
else
display dialog ("Votre dossier d'origine est :
" & le_dossier_memorise & "
Cliquez sur «Valider» ou désignez le dossier d'origine...") buttons {"Valider", "Chercher", "Sortir"} default button 1
set the button_pressed to the button returned of the result
if the button_pressed is "Valider" then
set out_folder to le_dossier_memorise as string
else if the button_pressed is "Chercher" then
set out_folder to (choose folder with prompt "Désigner le dossier d'origine :") as string
else
return
end if
end if
set le_dossier_a_memoriser to out_folder as string
open for access path_to_file_pref with write permission
write le_dossier_a_memoriser starting at 0 to path_to_file_pref
set eof path_to_file_pref to (length of le_dossier_a_memoriser)
close access path_to_file_pref
-------------------------
--Sélection du dossier in
set le_dossier_memorise to ""
try
set path_to_file_pref to dossier_pref & "TriPathIn" as alias
open for access path_to_file_pref with write permission
set le_dossier_memorise to read path_to_file_pref as string
close access path_to_file_pref
on error
tell application "Finder" to make new file at alias dossier_pref with properties {name:"TriPathIn", creator type:"????", file type:"pref", locked:false, busy status:false, short version:"", long version:""}
set path_to_file_pref to dossier_pref & "TriPathIn" as alias
end try
if le_dossier_memorise = "" then
display dialog "Désignez le dossier de destination..." buttons {"Chercher", "Sortir"} default button 1
if the button returned of the result is "Chercher" then
set in_folder to (choose folder with prompt "Désigner le dossier de destination :") as string
else
tell application "Finder" to delete dossier_pref & "TriPathIn"
return
end if
else
display dialog ("Votre dossier de destination est :
" & le_dossier_memorise & "
Cliquez sur «Valider» ou désignez le dossier de destination...") buttons {"Valider", "Chercher", "Sortir"} default button 1
set the button_pressed to the button returned of the result
if the button_pressed is "Valider" then
set in_folder to le_dossier_memorise as string
else if the button_pressed is "Chercher" then
set in_folder to (choose folder with prompt "Désigner le dossier de destination :") as string
else
return
end if
end if
set le_dossier_a_memoriser to in_folder as string
open for access path_to_file_pref with write permission
write le_dossier_a_memoriser starting at 0 to path_to_file_pref
set eof path_to_file_pref to (length of le_dossier_a_memoriser)
close access path_to_file_pref
-------------------------
--Premier récapitulatif et Option
display dialog ("Acceptez-vous les paramétrages par défaut :
Le dossier à traiter est :
- " & out_folder & "
Le dossier de destination est :
- " & in_folder & "
Les options sont :
- Traitement des fichiers «JPG» uniquement.
- Les sous-dossiers ne seront pas traités.
- Les doublons seront indexés.
- Les fichiers seront renommés.") buttons {"Valider", "Options", "Sortir"} default button 1
set the button_pressed to the button returned of the result
if the button_pressed is "Valider" then
set fileType to "JPG"
set Text_3 to "JPG"
set Double to "on"
set SubFolder to "off"
set Renommer to "on"
else if the button_pressed is "Options" then
--Choix des options
display dialog "Voulez-vous traiter les sous-dossiers ?" buttons {"Oui", "Non"} default button 2
if the button returned of the result is "Oui" then
set SubFolder to "on"
else
set SubFolder to "off"
end if
display dialog "Préciser ou sélectionner un type de fichier à traiter...
Pour sélectionner tous les types de fichiers, effacer le champ de saisie." default answer "JPG" buttons {"OK", "JPG", "MOV"} default button 1
copy the result as list to {Text_3, Valide_3}
if Valide_3 is "OK" then
set fileType to Text_3
else
set fileType to Valide_3
end if
display dialog "Que voulez-vous faire avec les doublons ?" buttons {"Ignorer", "Indexer", "Supprimer"} default button 2
set the Valide_4 to the button returned of the result
if the Valide_4 is "Indexer" then
set Double to "on"
else if the Valide_4 is "Ignorer" then
set Double to "off"
else
set Double to "kill"
end if
display dialog "Voulez-vous renommer les fichiers ?" buttons {"Oui", "Non"} default button 1
if the button returned of the result is "Oui" then
set Renommer to "on"
else
set Renommer to "off"
end if
--------------------
--Récupération des valeurs des options
if Text_3 is "" then
set Description_ext to "de tous les fichiers."
else
set Description_ext to ("des fichiers «" & fileType & "» uniquement.")
end if
if Valide_4 is "Indexer" then
set Description_doublon to "indexés."
else if Valide_4 is "Ignorer" then
set Description_doublon to "ignorés."
else if Valide_4 is "Supprimer" then
set Description_doublon to "supprimés."
end if
if Renommer is "on" then
set Description_Renommer to "seront renommés."
else if Renommer is "off" then
set Description_Renommer to "ne seront pas renommés."
end if
if SubFolder is "on" then
set Description_SubFolder to "seront traités."
else if SubFolder is "off" then
set Description_SubFolder to "ne seront pas traités."
end if
---------------------------------------
--Sous récapitulatif
display dialog ("Acceptez-vous les paramétrages par défaut :
Le dossier à traiter est :
- " & out_folder & "
Le dossier de destination est :
- " & in_folder & "
Les options sont :
- Traitement " & Description_ext & "
- Les sous-dossiers " & Description_SubFolder & "
- Les doublons seront " & Description_doublon & "
- Les fichiers " & Description_Renommer) buttons {"Trier", "Sortir"} default button 1
if the button returned of the result is "Sortir" then
return
end if
----------------------
else
return
end if
--Fin des récapitulatifs
-------------------
tell application "Finder"
if SubFolder is "off" then
if Text_3 is "" then
set itemGroup to (get every document file of folder out_folder)
else
set itemGroup to (get every document file of folder out_folder whose name extension is fileType)
end if
else if SubFolder is "on" then
if Text_3 is "" then
set itemGroup to (get every document file of entire contents of folder out_folder)
else
set itemGroup to (get every document file of entire contents of folder out_folder whose name extension is fileType)
end if
end if
set FolderSwitch to ("off") as string
set NewName to ("") as string
set OldfolderName to ("") as string
set myOldFolder to ("") as string
set folder_liste to {}
set folder_count to 0
set OldY to 0
repeat with x from 1 to count of itemGroup
set Doublon to 1
set groupItem to item x of itemGroup
--Récupérer le chemin du fichier
set New_out_folder to groupItem as string
set Nom_fichier to the name of groupItem
set nbrChar to (count of characters of Nom_fichier)
set nbrChar to -nbrChar - 1
set New_out_folder to text 1 thru nbrChar of (get New_out_folder)
---------------------------------
set {year:y} to the creation date of groupItem
set laDate to the creation date of groupItem
copy laDate to laDateBis
set the month of laDateBis to January
set m to (1 + (laDate - laDateBis + 1314864) div 2629728)
if m < 10 then
set m to ("0" & (m))
end if
set laDateEcrite to laDate as string
set folderName to ((m) & " - " & (3rd word of laDateEcrite) & " " & (y)) as string
if y ≠ OldY then
tell application "Finder"
try
make new folder at in_folder with properties {name:y}
end try
end tell
set OldY to y
set yearFolder to (in_folder & y)
end if
if folderName ≠ OldfolderName then
tell application "Finder"
try
make new folder at yearFolder with properties {name:folderName}
end try
end tell
set OldfolderName to folderName
end if
set myFolder to (yearFolder & ":" & folderName) as string
if myFolder is not in folder_liste then set folder_liste to folder_liste & myFolder
set Boucle to ("on")
repeat while (Boucle = "on")
if Doublon = 1 then
set NewName to the name of groupItem
else
tell application "Finder"
set AliasName to myPhoto as alias
set filePath to AliasName as text
set TID to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set fileName to last text item of filePath
if Doublon = 2 then
set AppleScript's text item delimiters to "."
set fileNamePart1 to text item 1 of fileName
set fileNamePart2 to text item 2 of fileName
set fileName to fileNamePart1 & " - copie " & Doublon - 1 & "." & fileNamePart2
set AppleScript's text item delimiters to TID
set name of AliasName to fileName
set NewName to fileName
else if Doublon > 2 then
set AppleScript's text item delimiters to " "
set fileNamePart1 to text item 1 of fileName
set AppleScript's text item delimiters to "."
set fileNamePart2 to text item 2 of fileName
set AppleScript's text item delimiters to ""
set fileName to fileNamePart1 & " - copie " & Doublon - 1 & "." & fileNamePart2
set AppleScript's text item delimiters to TID
set name of AliasName to fileName
set NewName to fileName
end if
end tell
end if
set myPhoto to ((New_out_folder) & (NewName)) as string
set Boucle to ("off")
tell application "Finder"
try
move myPhoto to myFolder without replacing
on error
if Double is "on" then
set Doublon to Doublon + 1
set Boucle to "on"
else if Double is "off" then
set Boucle to "off"
else if Double is "kill" then
delete groupItem
end if
end try
end tell
end repeat
end repeat
end tell
--Renommer les fichiers de chaque dossier traîté
if Renommer is "on" then
repeat with FolderToRename in folder_liste
tell application "Finder"
if Text_3 = "" then
set itemFileSorted to (get every document file of folder FolderToRename) sort by creation date
else
set itemFileSorted to (get every document file of folder FolderToRename whose name extension is fileType) sort by creation date
end if
set itemFile to reverse of itemFileSorted
set x to 0
repeat with FileToRename in itemFile
set x to x + 1
if x < 10 then set x to ("00" & x)
if x > 9 and x < 100 then
set x to ("0" & (x))
end if
set AliasName to FileToRename as alias
set filePath to AliasName as text
set TID to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set NewNameFile to last text item of filePath
set AppleScript's text item delimiters to "."
set theExtension to text item 2 of NewNameFile
set AppleScript's text item delimiters to ""
set NewNameFile to (x & "." & theExtension) as string
set AppleScript's text item delimiters to TID
set name of AliasName to NewNameFile
end repeat
if Text_3 = "" then
set itemFileSorted to (get every document file of folder FolderToRename)
else
set itemFileSorted to (get every document file of folder FolderToRename whose name extension is fileType)
end if
repeat with FileToRename in itemFileSorted
set AliasName to FileToRename as alias
set filePath to AliasName as text
set TID to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set NewNameFile to last text item of filePath
set AppleScript's text item delimiters to "."
set NumeroPhoto to text item 1 of NewNameFile
set theExtension to text item 2 of NewNameFile
set {year:y, day:d} to the creation date of FileToRename
set laDate to the creation date of FileToRename
set laDateEcrite to laDate as string
set FrenchJour to 1st word of laDateEcrite
set frenchMois to 3rd word of laDateEcrite
if d < 10 then
set d to ("0" & (d))
end if
set AppleScript's text item delimiters to ""
set NewNameFile to (NumeroPhoto & " - " & FrenchJour & " " & d & " " & frenchMois & " " & y & "." & theExtension) as string
set AppleScript's text item delimiters to TID
set name of AliasName to NewNameFile
end repeat
end tell
end repeat
end if
--Dialogue de fin
display dialog "Le traitement des fichiers est terminé." buttons {"Sortir", "Recommencer"} default button 1
if the button returned of the result is "Sortir" then
set tour to "off"
else
set tour to "on"
end if
end repeat
--Renommer les fichiers de dossiers non traités
else if the button returned of the result is "Renommer" then
set Reaname_tour to "on"
repeat while Reaname_tour is "on"
--Sélection du dossier des fichiers à renommer
set folder_liste to {}
set dossier_pref to (path to preferences) as string
set le_dossier_memorise to ""
try
set path_to_file_pref to dossier_pref & "RenamePath" as alias
open for access path_to_file_pref with write permission
set le_dossier_memorise to read path_to_file_pref as string
close access path_to_file_pref
on error
tell application "Finder" to make new file at alias dossier_pref with properties {name:"RenamePath", creator type:"????", file type:"pref", locked:false, busy status:false, short version:"", long version:""}
set path_to_file_pref to dossier_pref & "RenamePath" as alias
end try
if le_dossier_memorise = "" then
display dialog "Désignez le dossier des fichiers à renommer..." buttons {"Chercher", "Sortir"} default button 1
if the button returned of the result is "Chercher" then
set rename_folder to (choose folder with prompt "Désigner le dossier des fichiers à renommer :") as string
else
tell application "Finder" to delete dossier_pref & "RenamePath"
return
end if
else
display dialog ("Le dossier des fichiers à renommer est :
" & le_dossier_memorise & "
Cliquez sur «Valider» ou désignez le dossier des fichiers à renommer...") buttons {"Valider", "Chercher", "Sortir"} default button 1
set the button_pressed to the button returned of the result
if the button_pressed is "Valider" then
set rename_folder to le_dossier_memorise as string
else if the button_pressed is "Chercher" then
set rename_folder to (choose folder with prompt "Désigner le dossier des fichiers à renommer :") as string
else
return
end if
end if
set le_dossier_a_memoriser to rename_folder as string
open for access path_to_file_pref with write permission
write le_dossier_a_memoriser starting at 0 to path_to_file_pref
set eof path_to_file_pref to (length of le_dossier_a_memoriser)
close access path_to_file_pref
--Premier Récapitulatif
set {year:y, day:d} to the current date
set laDate to the current date
set laDateEcrite to laDate as string
set FrenchJour to 1st word of laDateEcrite
set frenchMois to 3rd word of laDateEcrite
set Name_Format to "001 - " & FrenchJour & " " & d & " " & frenchMois & " " & y & ".JPG" as string
display dialog ("Acceptez-vous les paramétrages par défaut :
Le dossier des fichiers à renommer est :
- " & le_dossier_memorise & "
Les options sont :
- Les sous-dossiers seront traités.
- Traitement des fichiers «JPG» uniquement.
- Les fichiers seront renommés au format :
" & Name_Format) buttons {"Valider", "Options", "Sortir"} default button 1
if the button returned of the result is "Valider" then
set SubFolder to "on"
set fileType to "JPG"
set Text_3 to "JPG"
set formatDate to "jour"
set button_pressed to "Dater"
else if the button returned of the result is "Options" then
display dialog "Voulez-vous traiter les sous-dossiers ?" buttons {"Oui", "Non"} default button 2
if the button returned of the result is "Oui" then
set SubFolder to "on"
set Description_SubFolder to "seront"
else
set SubFolder to "off"
set Description_SubFolder to "ne seront pas"
end if
display dialog "Préciser ou sélectionner un type de fichier à traiter...
Pour sélectionner tous les types de fichiers, effacer le champ de saisie." default answer "JPG" buttons {"OK", "JPG", "MOV"} default button 1
copy the result as list to {Text_3, Valide_3}
if Valide_3 is "OK" then
set fileType to Text_3
else
set fileType to Valide_3
end if
if fileType = "" then
set Description_Type to "Tous les fichiers seront traités."
else
set Description_Type to ("Seuls les fichiers de type «" & fileType & "» seront traités.")
end if
display dialog ("- Pour rennommer les fichiers au format :
" & Name_Format & "
cliquer \"Dater\"
- Pour numéroter les fichiers au format :
001.JPG
cliquer \"Numéroter\"
- Pour personnaliser les fichiers au format :
Perso 001.JPG
Saisir un nom et cliquer sur \"Personnaliser\"") default answer "Perso" buttons {"Dater", "Numéroter", "Personnaliser"} default button 1
copy the result as list to {personnalisation, button_pressed}
if button_pressed = "Dater" then
set Nom_Format to "Dater"
set Description_Format to Name_Format
else if button_pressed = "Numéroter" then
set Description_Format to "001.JPG"
else if button_pressed = "Personnaliser" then
set Description_Format to personnalisation & " 001.JPG"
end if
-- Deuxième Récapitulatif
display dialog ("Récapitulatif de vos paramètres :
Le dossier des fichiers à renommer est :
- " & le_dossier_memorise & "
Les options sont :
- Les sous-dossiers " & Description_SubFolder & " traités.
- " & Description_Type & "
- Les fichiers seront renommés au format :
" & Description_Format) buttons {"Trier", "Sortir"} default button 1
if the button returned of the result is "Sortir" then
return
end if
else if the button returned of the result is "Sortir" then
return
end if
tell application "Finder"
--set folder_liste to folder_liste & myFolder
if SubFolder is "off" then
set folder_liste to folder_liste & rename_folder
else if SubFolder is "on" then
try
set folder_liste to (get every folder of entire contents of folder rename_folder)
set folder_liste to folder_liste & rename_folder
on error
try
set folder_liste to (get every folder of folder rename_folder)
--set folder_liste to folder_liste & rename_folder
end try
set folder_liste to folder_liste & rename_folder
end try
--return folder_liste
end if
repeat with FolderToRename in folder_liste
set RenamedFolder to FolderToRename as string
--return RenamedFolder
tell application "Finder"
if Text_3 = "" then
set itemFileSorted to (get every document file of folder RenamedFolder) sort by creation date
else
set itemFileSorted to (get every document file of folder RenamedFolder whose name extension is fileType) sort by creation date
--return itemFileSorted
end if
set itemFile to reverse of itemFileSorted
set x to 0
repeat with FileToRename in itemFile
set x to x + 1
if x < 10 then set x to ("00" & x)
if x > 9 and x < 100 then
set x to ("0" & (x))
end if
set AliasName to FileToRename as alias
set filePath to AliasName as text
set TID to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set NewNameFile to last text item of filePath
set AppleScript's text item delimiters to "."
set theExtension to text item 2 of NewNameFile
set AppleScript's text item delimiters to ""
set NewNameFile to (x & "." & theExtension) as string
set AppleScript's text item delimiters to TID
set name of AliasName to NewNameFile
end repeat
if button_pressed = "Dater" then
if Text_3 = "" then
set itemFileSorted to (get every document file of folder RenamedFolder)
else
set itemFileSorted to (get every document file of folder RenamedFolder whose name extension is fileType)
end if
repeat with FileToRename in itemFileSorted
set AliasName to FileToRename as alias
set filePath to AliasName as text
set TID to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set NewNameFile to last text item of filePath
set AppleScript's text item delimiters to "."
set NumeroPhoto to text item 1 of NewNameFile
set theExtension to text item 2 of NewNameFile
set {year:y, day:d} to the creation date of FileToRename
set laDate to the creation date of FileToRename
set laDateEcrite to laDate as string
set FrenchJour to 1st word of laDateEcrite
set frenchMois to 3rd word of laDateEcrite
if d < 10 then
set d to ("0" & (d))
end if
set AppleScript's text item delimiters to ""
set NewNameFile to (NumeroPhoto & " - " & FrenchJour & " " & d & " " & frenchMois & " " & y & "." & theExtension) as string
set AppleScript's text item delimiters to TID
set name of AliasName to NewNameFile
end repeat
end if
if button_pressed = "Personnaliser" then
if Text_3 = "" then
set itemFileSorted to (get every document file of folder RenamedFolder)
else
set itemFileSorted to (get every document file of folder RenamedFolder whose name extension is fileType)
end if
repeat with FileToRename in itemFileSorted
set AliasName to FileToRename as alias
set filePath to AliasName as text
set TID to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set NewNameFile to last text item of filePath
set AppleScript's text item delimiters to "."
set NumeroPhoto to text item 1 of NewNameFile
set theExtension to text item 2 of NewNameFile
set AppleScript's text item delimiters to ""
set NewNameFile to (personnalisation & " " & NumeroPhoto & "." & theExtension) as string
set AppleScript's text item delimiters to TID
set name of AliasName to NewNameFile
end repeat
end if
end tell
end repeat
end tell
--Dialogue de fin
display dialog "Le traitement des fichiers est terminé." buttons {"Sortir", "Recommencer"} default button 1
if the button returned of the result is "Sortir" then
set Reaname_tour to "off"
else
set Rename_tour to "on"
end if
end repeat
else
--Redater les fichiers
set datetour to "on"
repeat while datetour is "on"
display dialog "Désignez le dossiers ou le(s) fichier(s) à traiter..." buttons {"Dossier", "Fichier(s)", "Sortir"} default button 2
if the button returned of the result is "Fichier(s)" then
set ReDate_files to (choose file with prompt "Désigner le(s) fichier(s) à traiter :" with multiple selections allowed)
else if the button returned of the result is "Dossier" then
set ReDate_files to {}
set ReDate_folder to (choose folder with prompt "Désigner le dossier à traiter :")
tell application "Finder"
set itemFolderSorted to (get every document file of folder ReDate_folder) sort by creation date
set itemFolder to reverse of itemFolderSorted
end tell
repeat with Item_folder in itemFolder
set Item_folder to Item_folder as alias
set ReDate_files to ReDate_files & Item_folder
end repeat
else
return
end if
set Aujourdhui to current date
set jour to day of Aujourdhui
set annee to year of Aujourdhui
copy Aujourdhui to AujourdhuiBis
set the month of AujourdhuiBis to January
set mois to (1 + (Aujourdhui - AujourdhuiBis + 1314864) div 2629728)
if mois < 10 then
set mois to ("0" & (mois))
end if
if jour < 10 then
set jour to ("0" & (jour))
end if
set Aujourdhui_perso to (jour & "/" & mois & "/" & annee) as string
display dialog "Entrez la nouvelle date au format " & Aujourdhui_perso default answer Aujourdhui_perso buttons {"Valider", "Sortir"} default button 1
copy the result as list to {NewDateBrute, button_pressed}
if button_pressed is "Sortir" then return
repeat while length of NewDateBrute ≠ 10
display dialog "Le format de la date n'est pas respecté. Vous ne pouvez utiliser que des chiffres et des «/». Les jours et les mois doivent comporter 2 chiffres. L'année doit comporter 4 chiffres. Veuillez ressaisir une date." default answer Aujourdhui_perso buttons {"Valider", "Sortir"} default button 1
copy the result as list to {NewDateBrute, button_pressed}
if button_pressed is "Sortir" then return
end repeat
display dialog "" buttons {"Date de création", "Date de modification", "Les deux"} default button 1
if the button returned of the result is "Date de création" then
set DateChange to "creation"
else if the button returned of the result is "Date de modification" then
set DateChange to "modification"
else
set DateChange to "lesdeux"
end if
set NewJour to items 1 thru 2 of NewDateBrute
set NewMois to items 4 thru 5 of NewDateBrute
set NewAnnee to items 7 thru 10 of NewDateBrute
set heure to 12 as string
set minute to 0
set seconde to 0
tell application "Finder"
repeat with NewFileToRedate in ReDate_files
set seconde to seconde + 1
if seconde = 60 then
set seconde to 0
set minute to minute + 1
end if
if seconde < 10 then set seconde to ("0" & seconde)
if minute < 10 then set minute to ("0" & minute)
set NewDate to ("\"" & NewMois & "/" & NewJour & "/" & NewAnnee & " " & heure & ":" & minute & ":" & seconde & "\"") as string
tell application "Finder"
set NewFileToRedate to POSIX path of NewFileToRedate
set TID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {" "}
set NewFileToRedate to text items of NewFileToRedate
set AppleScript's text item delimiters to {"\\ "}
set NewFileToRedate to NewFileToRedate as Unicode text
set AppleScript's text item delimiters to {""}
set TID to AppleScript's text item delimiters
set NewFileToRedate to " " & NewFileToRedate
if DateChange = "creation" then
do shell script "SetFile -d " & NewDate & " " & NewFileToRedate
else if DateChange = "modification" then
do shell script "SetFile -md " & NewDate & " " & NewFileToRedate
else
do shell script "SetFile -md " & NewDate & " " & NewFileToRedate
do shell script "SetFile -d " & NewDate & " " & NewFileToRedate
end if
end tell
end repeat
end tell
display dialog "Le traitement des fichiers à redater est terminé." buttons {"Sortir", "Recommencer"} default button 1
if the button returned of the result is "Sortir" then
set datetour to "off"
else
set datetour to "on"
end if
end repeat
end if |
Partager