Search code examples
macosshelldecimal-point

Is there a way to return the current region-based decimal and thousands separators in a shell script on macOS?


I'm wanting a way to return the current decimal and thousands separators based on the region setting. I know that you can get the language-based separators using locale decimal_point and locale thousands_sep, and if you have custom separators set you can use defaults read -g AppleICUNumberSymbols, but I can't find a way to return the region-based values.

For example, in the Language & Region System Preferences page, the preferred language is set to English and the Region is set to France. I want something that will return " " for the thousands separator and "," for the decimal separator.


Solution

  • Okay, so based on Larme's suggestions of Foundation.framework, I've come up with the following solution that will give me what I want in a shell script using osascript to access NSNumberFormatter:

    osascript -e 'use framework "Foundation"' -e 'return (decimalSeparator of init() of alloc() of NSNumberFormatter of current application as string)'