I have a script that will put a md5 checksum and file size into a txt doc for later use.
the code i’m using for the file size is
set fileSize to currentItem
set dataSize to size of (info for fileSize) as string
occasionally i get a file size resulting in a number like 1.37811096099E+11. would it have to do with the “as string” line? any one else have this issue before?
set theSize to 5.7667697E+8
set textString1 to my formatSize(theSize, "MB")
set textString2 to my formatSize(theSize, "GB")
on formatSize(value, mode)
if mode = "MB" then
set value to value / (1024 ^ 2)
else if mode = "GB" then
set value to value / (1024 ^ 3)
end if
if value > 1000.0 then
return ((round value) as text) & space & mode
else
return (((round (value * 100)) / 100) as text) & space & mode
end if
end formatSize
textString1 & return & textString2
AppleScripts integers are usually limited to 29 bits, anything with a larger magnitude larger is “promoted” to a real (aka float) which is always formatted like that in AppleScript. You could try something like Nigel Garvey’s numToStr to undo the scientific notation.
I’m sort of new to AppleScript and haven’t really used subroutines before. I’m trying the numToStr . Have you used this before? I’m trying to call to the “return outputString” that he has in this script to display the correct bits but it just says its not valid.