-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathSelected Items Size.applescript
94 lines (77 loc) · 3.36 KB
/
Selected Items Size.applescript
1
#Selected Items Size AppleScript#2018 (ɔ) jraulc at gmail dot comset localeString to user locale of (get system info)#you can localize to your language hereif localeString starts with "es" then set okButton to "Aceptar" set noSelectionString to "Por favor seleccione al menos dos items para calcular su tamaño." set totalSizeString to "Tamaño total seleccionado: " set selectedItemsString to " items seleccionados en: " & return set reallyString to "Es en serio?" & return set tooBigString to "Es en serio?" & return & return & "Solo puedo decir esto 'El tamaño total de los items seleccionados es mayor a 1 ExaByte.'"else #default if not match with the localized language set okButton to "OK" set noSelectionString to "Please select at least two items to calculate it size." set totalSizeString to "Total selected size is: " set selectedItemsString to " items selected at: " & return set reallyString to "Really?" & return set tooBigString to "Really?" & return & return & "I only can say this 'The total size of selected items is bigger than 1 ExaByte.'"end ifset allItemsSize to ""set itemsCount to 0tell application "Finder" with timeout of 3600 seconds set selectedItems to selection as list if selectedItems is {} then display dialog noSelectionString buttons {okButton} default button okButton with icon stop error number -128 else set itemsPath to POSIX path of (folder of the front window as alias) set itemsCount to 0 repeat with iCount in selectedItems set itemsCount to itemsCount + 1 set lastItemSize to size of (info for (iCount as alias)) set allItemsSize to allItemsSize + lastItemSize end repeat end if end timeoutend tellset {sizeInUnits, stringUnits} to converSize(allItemsSize)if itemsCount > 1 then set summaryAlert to (itemsCount as string) & selectedItemsString & itemsPath & return & totalSizeString & return & sizeInUnits & " " & stringUnitselse set summaryAlert to reallyString & (itemsCount as string) & selectedItemsString & itemsPath & return & totalSizeString & return & sizeInUnits & " " & stringUnitsend iftell application "Finder" to display alert summaryAlerton converSize(allBytesSize) #convert bytes size to human readable memory size and return it with the correct unit. if allBytesSize > 1.15292150460685E+18 then display dialog tooBigString buttons {okButton} default button okButton with icon caution error number -128 end if if allBytesSize < 1.15292150460685E+18 and allBytesSize > 1.12589990684262E+15 then set totalSize to (round (100 * (allBytesSize / 1.0E+15))) / 100 set Units to "PB" end if if allBytesSize < 1.12589990684262E+15 and allBytesSize > 1.099511627776E+12 then set totalSize to (round (100 * (allBytesSize / 1.0E+12))) / 100 set Units to "TB" end if if allBytesSize < 1.099511627776E+12 and allBytesSize > 1.073741824E+9 then set totalSize to (round (100 * (allBytesSize / 1.0E+9))) / 100 set Units to "GB" end if if allBytesSize < 1.073741824E+9 and allBytesSize > 1048576 then set totalSize to (round (100 * (allBytesSize / 1000000))) / 100 set Units to "MB" end if if allBytesSize < 1048576 and allBytesSize > 1024 then set totalSize to (round (100 * (allBytesSize / 1000))) / 100 set Units to "KB" end if if allBytesSize < 1024 then set totalSize to allBytesSize set Units to "bytes" end if return {totalSize, Units} end converSize