--
on open these_items
--
set someNumber to my totalFromSelection(these_items)
if (someNumber < 0) then
--
display alert "Achtung" as critical message "Die Gesamtsumme der markierten Dateien/Ordner konnte nicht ermittelt werden. Ein oder mehrere Namen haben nicht das richtige Format."
--
return false
--
end if
--
set someText to number_to_string(someNumber)
--
display alert "Ergebnis" as informational message "Die Gesamtsumme beträgt " & someText & " Euro."
--
return true
--
end open
--
on totalFromSelection(allItems)
--
if ((count of allItems) < 1) then
return -1
end if
--
set total to 0
--
repeat with nItem in allItems
--
set someNumber to my totalFromItem(nItem)
if (someNumber < 0) then
return -2
end if
--
set total to total + someNumber
--
end repeat
--
return total
--
end totalFromSelection
--
on totalFromItem(aItem)
--
tell application "Finder"
set someText to name of aItem
end tell
--
set someNumber to my totalFromTextWithDelimiter(someText, "€")
if (someNumber ≥ 0) then
return someNumber
end if
--
set someNumber to my totalFromTextWithDelimiter(someText, "EUR")
if (someNumber ≥ 0) then
return someNumber
end if
--
return -1
--
end totalFromItem
--
on totalFromTextWithDelimiter(someText, someDelimiter)
--
set AppleScript's text item delimiters to someDelimiter
--
set allItems to text items of someText
if ((count of allItems) < 2) then
return -1
end if
--
set someText to first item of allItems
--
set AppleScript's text item delimiters to " - "
--
set allItems to text items of someText
if ((count of allItems) < 2) then
return -2
end if
--
set someText to last item of allItems
--
set someNumber to someText as number
if (someNumber < 0) then
return -3
end if
--
return someNumber
--
end totalFromTextWithDelimiter
--
on number_to_string(this_number)
--
-- http://www.macosxautomation.com/applescript/sbrt/sbrt-02.html
--
set AppleScript's text item delimiters to ""
--
set this_number to this_number as string
--
set x to the offset of "," in this_number
--
if this_number contains "E+" then
set y to the offset of "+" in this_number
set z to the offset of "E" in this_number
set the decimal_adjust to characters (y - (length of this_number)) thru ¬
-1 of this_number as string as number
if x is not 0 then
set the first_part to characters 1 thru (x - 1) of this_number as string
else
set the first_part to ""
end if
set the second_part to characters (x + 1) thru (z - 1) of this_number as string
set the converted_number to the first_part
repeat with i from 1 to the decimal_adjust
try
set the converted_number to ¬
the converted_number & character i of the second_part
on error
set the converted_number to the converted_number & "0"
end try
end repeat
set someText to this_number
set someText to characters 1 thru (z - 1) of someText as string
set someText to characters (x + 1 + decimal_adjust) thru (length of someText) of someText as string
set converted_number to my comma_delimit(converted_number)
set converted_number to converted_number & "," & someText
return the converted_number
else
--
set someText to this_number
set someText to characters 1 thru (x - 1) of someText as string
set someText to my comma_delimit(someText)
--
if (x > 0) then
set this_number to characters (x + 1) thru (length of this_number) of this_number as string
else
set this_number to "00"
end if
--
set someText to someText & "," & this_number
--
return someText
--
end if
end number_to_string
on comma_delimit(this_number)
--
-- http://www.macosxautomation.com/applescript/sbrt/sbrt-02.html
--
set AppleScript's text item delimiters to ""
--
set the num_length to the length of this_number
set the this_number to (the reverse of every character of this_number) as string
set the new_num to ""
repeat with i from 1 to the num_length
if i is the num_length or (i mod 3) is not 0 then
set the new_num to (character i of this_number & the new_num) as string
else
set the new_num to ("." & character i of this_number & the new_num) as string
end if
end repeat
return the new_num
end comma_delimit