• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Questions About Bundled Scripts
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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)"

-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>

 _______________________________________________
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

References: 
 >Questions About Bundled Scripts (From: Alex Hall <email@hidden>)

  • Prev by Date: Re: Questions About Bundled Scripts
  • Next by Date: Re: delay doesn't work when applet is not frontmost
  • Previous by thread: Re: Questions About Bundled Scripts
  • Next by thread: Error handling?
  • Index(es):
    • Date
    • Thread