Nome tips (domanda)

Testo (risposta)

property Tempo : "60" -- tempo necessario prima di dare forfait, aumenta questo valore se ottieni un errore di timeout
property OK : " OK "
property Annulla : " Annulla "
property Dettagli : " Dettagli "

tell application "Finder"
                try
                                set Cartella to selection
                                set SCartella to (Cartella as string)
                                if Cartella = {} or (count of Cartella) > 1 then error
                on error
                                error return & "Selezionare una cartella prima di attivare questo script." & return
                end try
                set TipoCartella to kind of first folder of startup disk
                if kind of (alias SCartella) is TipoCartella then
                                with timeout of Tempo seconds
                                                try
                                                                set NumeroTotale to count every item in entire contents of alias SCartella
                                                                set NumeroCartelle to count every folder in alias SCartella
                                                                set Numero to count items in alias SCartella
                                                                if Numero = 1 then
                                                                                set e to "elemento"
                                                                else
                                                                                set e to "elementi"
                                                                end if
                                                                if NumeroCartelle = 1 then
                                                                                set p to "cartella"
                                                                else
                                                                                set p to "cartelle"
                                                                end if
                                                                if NumeroCartelle is greater than or equal to 1 then
                                                                                set Messaggio to "La cartella selezionata contiene " & (Numero as string) & " " & e & ", di cui " & (NumeroCartelle as string) & " " & p & "." & return & return & "Gli elementi contenuti nella cartella “" & (name of alias SCartella) & "” e nelle incluse subcartelle, in totale sono " & (NumeroTotale as string) & "."
                                                                                set Pulsanti to {Dettagli, OK}
                                                                else
                                                                                set Messaggio to "La cartella selezionata contiene " & (Numero as string) & " " & e & "."
                                                                                set Pulsanti to OK
                                                                end if
                                                                if button returned of my Dialogo(Messaggio, Pulsanti, OK, 1) is equal to Dettagli then
                                                                                set NumeroApp to 0
                                                                                set NumeroDoc to 0
                                                                                set NumeroFldr to 0
                                                                                set Ora to time of (current date)
                                                                                set Contatore to 1
                                                                                set Elementi to every item in entire contents of alias SCartella
                                                                                repeat with Elemento in Elementi
                                                                                                if class of Elemento = application file then
                                                                                                                set NumeroApp to NumeroApp + 1
                                                                                                else if class of Elemento = folder then
                                                                                                                set NumeroFldr to NumeroFldr + 1
                                                                                                else
                                                                                                                set NumeroDoc to NumeroDoc + 1
                                                                                                end if
                                                                                                if (time of (current date)) - (Tempo / 2) > Ora then
                                                                                                                ignoring application responses
                                                                                                                                my Dialogo("Elaborazione in corso..." & return & return & "Attendere..." & return & return & "Elemento " & (Contatore as string) & " di " & ((count of items in Elementi) as string), "      ", 1, 1)
                                                                                                                end ignoring
                                                                                                                set Ora to time of (current date)
                                                                                                end if
                                                                                                set Contatore to Contatore + 1
                                                                                end repeat
                                                                                my Dialogo("Contenuti in “" & (name of alias SCartella) & "”:" & return & return & ¬
                                                                                                " Cartelle: " & return & " " & (NumeroFldr as string) & return & return & ¬
                                                                                                " Documenti: " & return & " " & (NumeroDoc as string) & return & return & ¬
                                                                                                " Applicazioni: " & return & " " & (NumeroApp as string) & return, OK, OK, 1)
                                                                end if
                                                on error T number N
                                                                set TempoT to (Tempo / 60) as integer
                                                                if TempoT = 1 then
                                                                                set m to "minuto"
                                                                else
                                                                                set m to "minuti"
                                                                end if
                                                                my Dialogo((N as string) & " - L'elemento selezionato contiene troppi elementi, richiederebbe più di " & (TempoT as string) & " " & m & " per completare l'elaborazione.", Annulla, Annulla, 0)
                                                end try
                                end timeout
                else
                                my Dialogo("L'elemento selezionato non è una cartella", Annulla, Annulla, 0)
                end if
end tell

on Dialogo(Testo, Bottoni, Pulsante, Icona)
                tell current application
                                return (display dialog Testo buttons Bottoni default button Pulsante with icon Icona giving up after Tempo)
                end tell
end Dialogo