Re: Questions About Bundled Scripts
Re: Questions About Bundled Scripts
- Subject: Re: Questions About Bundled Scripts
- From: Shane Stanley <email@hidden>
- Date: Sat, 07 Mar 2015 20:15:52 +1100
On 7 Mar 2015, at 3:38 pm, Alex Hall <email@hidden> wrote:
converting numbers to megabytes or gigabytes
BTW, there's a formatter specifically for that task, NSByteCountFormatter. For example:
0000.001 [11] set theResult to (current application's NSByteCountFormatter's stringFromByteCount:123456789 countStyle:(current application's NSByteCountFormatterCountStyleFile)) as text --> "123.5 MB" 0000.002 [12] set theResult to (current application's NSByteCountFormatter's stringFromByteCount:123456789 countStyle:(current application's NSByteCountFormatterCountStyleMemory)) as text --> "117.7 MB"
And:
set theFormatter to current application's NSByteCountFormatter's alloc()'s init() theFormatter's setCountStyle:(current application's NSByteCountFormatterCountStyleMemory) theFormatter's setAllowsNonnumericFormatting:true theFormatter's setIncludesActualByteCount:true (theFormatter's stringFromByteCount:1.23456789E+9) as text --> "1.15 GB (1,234,567,890 bytes)" (theFormatter's stringFromByteCount:12345678) as text
--> "11.8 MB (12,345,678 bytes)"
|
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden