Voici ma situation. J'ai créé un AppleScript pour nettoyer mon bureau. Il sélectionne tous les fichiers et dossiers de mon bureau, crée un nouveau dossier avec un nom et un format de date spécifiques, et déplace tous les fichiers de mon bureau vers le nouveau dossier. Ce script fonctionne à merveille jusqu'à ce que je me rende compte qu'il y a parfois des fichiers ou des dossiers que je souhaite conserver sur mon bureau. Ma solution consistait à ouvrir la fenêtre d'information pour chaque fichier ou dossier que je souhaitais conserver sur mon bureau, et à sélectionner l'option "verrouiller" dans la fenêtre d'information.
Mon problème est qu'à cause des fichiers verrouillés, le script ne peut pas s'exécuter complètement sans afficher un message d'erreur. Si je clique sur "OK" sur le message d'erreur, le script se termine et déplace tous les fichiers à l'exception de ceux qui sont verrouillés.
Je préférerais ne pas avoir à franchir cette étape supplémentaire en cliquant sur le bouton "OK". J'ai essayé d'ajouter des actions d'événements système au script pour cliquer automatiquement sur le bouton "ok", mais cela n'a pas fonctionné.
Je commence à penser que la seule vraie solution serait de ne pas sélectionner ces fichiers ou dossiers verrouillés. C'est là que je suis perdu. Quelqu'un peut-il m'indiquer comment éviter de sélectionner les fichiers verrouillés en premier lieu ?
Voici le script dans son intégralité.
set scriptPath to (load script file "Macintosh HD:Users:Smokestack:Library:Mobile Documents:com~apple~ScriptEditor2:Documents:Cleanup Desktop.scptd:Contents:Resources:Scripts:Current Time A.M. P.M. And Short Date.scpt")
tell scriptPath
timeandDate() -- This will get the time and date in this format "05/31/2017 @ 9:10:48 PM" called from the loaded script file above
end tell
set timeandDate to the result -- This will copy the time and date results from the previous step and and set it as this new variable
tell application "Finder"
if running then
close every window
activate
make new Finder window
set target of Finder window 1 to folder "Desktop" of folder "Smokestack" of folder "Users" of startup disk
end if
open Finder window 1
activate
end tell
delay 1
tell application "System Events"
key code 0 using (command down) -- This will select all files and folders on the desktop in the active finder window
end tell
tell application "Finder"
set these_items to the selection
set destinationFolder to make new folder at POSIX file "/Users/Smokestack/Jimz_Important_Stuff/Desktop_Cleanups/" with properties {name:timeandDate}
move these_items to destinationFolder
reveal destinationFolder
end tell
Voici une version révisée du script sans appeler les gestionnaires à partir de fichiers externes
on timeandDate()
set CurrentTime to (time string of (current date))
set AppleScript's text item delimiters to ","
set theLongDate to (current date)
set theLongDate to (date string of theLongDate)
set currentMonth to (word 1 of text item 2 of theLongDate)
set currentDay to (word 2 of text item 2 of theLongDate)
set currentYear to (word 1 of text item 3 of theLongDate)
set monthList to {January, February, March, April, May, June, July, August, September, October, November, December}
repeat with x from 1 to 12
if currentMonth = ((item x of monthList) as string) then
set theRequestNumber to (text -2 thru -1 of ("0" & x))
exit repeat
end if
end repeat
set currentMonth to theRequestNumber
set currentDay to (text -2 thru -1 of ("0" & currentDay))
set theShortDate to (currentMonth & "/" & currentDay & "/" & currentYear) as string
set CurrentTime to (time string of (current date))
set CurrentTimeandShortDate to (theShortDate & " @ " & CurrentTime)
set AppleScript's text item delimiters to ""
end timeandDate
timeandDate()
set timeandDate to the result
tell application "Finder"
close every window
activate
make new Finder window
set target of Finder window 1 to folder "Desktop" of folder "Smokestack" of folder "Users" of startup disk
select every file of the front Finder window
delay 1
set these_items to the selection
set destinationFolder to make new folder at POSIX file "/Users/Smokestack/Jimz_Important_Stuff/Desktop_Cleanups/" with properties {name:timeandDate}
try
move these_items to destinationFolder
end try
reveal destinationFolder
end tell
Après avoir apporté quelques modifications au script, tant que les éléments verrouillés sur mon bureau ne sont que des dossiers et non des fichiers, ce script fonctionne à merveille. Cependant, il génère toujours une erreur s'il y a des fichiers individuels verrouillés.