Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Where does Script Editor get its locale settings?

I have been trying to use Script Editor to work around a problem with a particular app which has some display problems if opened from Launchpad but works perfectly if launched from Terminal.


I'd assumed that if I used Script Editor to run the command line that it would have the same result as launching from Terminal but I was wrong, it does not get around the problem.


Is there a way to make scripts run in Script Editor to pick up the same locale settings as Terminal? I have not changed the locale settings in terminal at any time since installing Mojave so it is picking up the information from setting made in the GUI.

iMac 27″, macOS 10.14

Posted on Nov 27, 2020 5:13 PM

Reply
7 replies

Nov 28, 2020 11:17 AM in response to gakushaburu

Executing Commands

The direct parameter of the do shell script command is a string containing the shell code you want to execute, as demonstrated in Listing 39-1, which simply lists a directory.

APPLESCRIPT


Open in Script Editor

Listing 39-2AppleScript: Concatenating a command with a value

  1. set theHostName to "www.apple.com"
  2. do shell script "ping -c1 " & theHostName


https://developer.apple.com/library/archive/documentation/LanguagesUtilities/Conceptual/MacAutomationScriptingGuide/CallCommandLineUtilities.html

Nov 29, 2020 4:19 AM in response to gakushaburu

use scripting additions

do shell script "export LC_CTYPE=en_US.UTF-8;locale"


Discussed in a Nov. 2012 stackoverflow article by C.O. from How to use UTF-8 encoded command in AppleScript's do shell script.


An old article, that still pertains (tested Big Sur on an M1 mini) as you can see from the above code. Replace locale with your program name.

Nov 28, 2020 4:51 PM in response to gakushaburu

The do shell script restricted Bash shell gets its locale information by invoking /etc/bashrc, which in turn, invokes /etc/bashrc_Apple_Terminal. This ensures that all locale oriented constants are set to "C", because it is treated like an interactive shell. You can verify this:


use scripting additions
set localeList to paragraphs of (do shell script "locale")
log localeList as list


The default login Bash shell invoked by the Terminal application has its locale entities set to en_US.UTF-8. You can verify this by running locale in the Bash (or Zsh) shell.

Nov 29, 2020 2:40 AM in response to VikingOSX

Thank you.


As you say, using Script Editor everything is set to "C" in the locale. This is what is causing me the problem as I need a UTF-8 environment for the program to run as it should but don't want to have to run it from within Terminal every time. I had assumed that the default locales would be the same in both environments.


I suppose I'm going to have to set LC_CTYPE in the script before doing anything else.

Where does Script Editor get its locale settings?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.