Toggle "Language & Region" Sys Prefs w/ Applescript

I frequently need to toggle the "Language & Region" of my System Preferences between 2 advanced settings - incl custom date formats and currency formats for each one. Thre is no quick way of doing this. ( Open sys prefs, choose "region>country", select "advanced", change date format, change currency format, etc...) I have to do this because the accounting program I use for different sets of books draws its settings from the Sys Prefs.

Is there a way of using Applescript and/or Automator to make a quick switcher (desktop icon, menu bar dropdown, etc) that will store the settings and then toggle quickly between them?

MacBook Pro, OS X Yosemite (10.10.2)

Posted on Mar 18, 2015 4:21 AM

Reply
12 replies
Sort By: 

Mar 18, 2015 8:51 AM in response to VictorWhisky

The following script can toggle the "Language & Region" preferences between United States and France. However, since the currency and date format seem to adjust automatically to the selected country, I wonder why you should have to change them.


property theSettings : {"", ""}


set settings1 to {"Americas", "United States"}

set settings2 to {"Europe", "France"}


if theSettings is settings1 then

set theSettings to settings2

else

set theSettings to settings1

end if


set {theRegion, theCountry} to theSettings


tell application "System Preferences"

activate

set current pane to paneid "com.apple.Localization"

tell application "System Events"

tell window "Language & Region" of process "System Preferences"

tell pop up button "Region:" of group 1

delay 0.25

click

delay 0.25

clickmenu itemtheRegion of menu 1

delay 0.25

clickmenu itemtheCountry of menu 1 of menu itemtheRegion of menu 1

end tell

end tell

end tell

quit

end tell


theSettings

Reply

Mar 18, 2015 9:56 AM in response to Pierre L.

Pierre,


For my first region, America, the standard system settings are fine, but for the second region (South Africa, in my case) our accounts were set up with 3 nonstandard features in the advanced tab which need to be manually set each time:


1) Advanced>General>Number Seperators>Grouping: "," (comma separates thousands)

2) Advanced>General>Currency>Grouping: "," (comma separates thousands)

3) Advanced>Dates>Short: dd/MM/y (day/month/year)


Do you know of any way these could be included in your script for the one region?


Thanks!

Reply

Mar 18, 2015 2:23 PM in response to VictorWhisky

The following version of the script should do what you are asking for:


set settings1 to {"Americas", "United States"}

set settings2 to {"Africa", "South Africa"}


tell application "System Preferences"

activate

set current pane to paneid "com.apple.Localization"

end tell


tell application "System Events"

tell window "Language & Region" of process "System Preferences"

if (value of pop up button "Region:" of group 1) is "United States" then

set theSettings to settings2

else

set theSettings to settings1

end if

set {theRegion, theCountry} to theSettings

tell pop up button "Region:" of group 1

delay 0.25

click

clickmenu itemtheRegion of menu 1

clickmenu itemtheCountry of menu 1 of menu itemtheRegion of menu 1

end tell

if theCountry is "South Africa" then

clickbutton "Advanced…"

delay 0.25

tell tab group 1 of sheet 1

set focused of combo box 1 to true

keystroke "a" using {command down}

keystroke "," & tab & tab

delay 0.25

keystroke "a" using {command down}

keystroke "," & tab & tab

delay 0.25

clickradio button "Dates"

keystroke "a" usingcommand down

set the clipboard to "dd/MM/y"

keystroke "v" usingcommand down

delay 0.25

keystrokereturn

end tell

end if

end tell

keystroke "w" using {command down}

end tell

Reply

Mar 19, 2015 12:05 AM in response to Pierre L.

Thanks, Pierre - that does the trick perfectly!


For anyone else following this - you may also need to allow this script to control your computer in the System Preferences > Security & Privacy pane, before it works. Depending on how you're running it, this might be SystemUIServer or Script Editor or your Automator app, if you're embedding this script in an automator app.

Reply

Jun 2, 2015 7:38 AM in response to Pierre L.

Hi Pierre,


Hope you don't mind me butting in on this thread but your solution is just what I was looking for, except to toggle between German and United Kingdom. I've got the script working for the two countries but I want to specify Euros as the currency for the United Kingdom region, rather than British Pounds. This is the only customisation that I need in my settings. Could you help me as to how I get to / set Euros in the currency drop down.


Many thanks in advance,


Steve

Reply

Jun 2, 2015 8:11 AM in response to MucSteve

The following should do the trick:

set settings1 to {"Europe", "Germany"}

set settings2 to {"Europe", "United Kingdom"}


tell application "System Preferences"

activate

set current pane to paneid "com.apple.Localization"

end tell


tell application "System Events"

tell process "System Preferences"

tell window "Language & Region"

if (value of pop up button "Region:" of group 1) is in settings1 then

set {theRegion, theCountry} to settings2

else

set {theRegion, theCountry} to settings1

end if

tell pop up button "Region:" of group 1

delay 0.25

click

clickmenu itemtheRegion of menu 1

clickmenu itemtheCountry of menu 1 of menu itemtheRegion of menu 1

end tell

if theCountry is in settings2 then

clickbutton "Advanced…"

delay 0.25

tell tab group 1 of sheet 1

clickpop up button "Currency:"

keystroke "Euro" & return & return

end tell

end if

keystroke "w" using {command down}

end tell

end tell

end tell

Reply

Jun 3, 2015 5:50 AM in response to Pierre L.

Hi Pierre,


Sorry to be pestering you again – I realised later that my MacBook Pro defaults to using a slash as a delimiter in the short date field for both the UK and German locales. I had changed this manually to full stops but now I'm changing region using the AppleScript, the delimiter defaults back to the slash, i.e. 03/06/2015 whereas I want 03.06.2015.


I've tried solving this myself by adding the following code to your script:

set settings1 to {"Europe", "Germany"}

set settings2 to {"Europe", "United Kingdom"}


tell application "System Preferences"


activate

set current pane to pane id "com.apple.Localization"

end tell


tell application "System Events"

tell process "System Preferences"

tell window "Language & Region"

if (value of pop up button "Region:" of group 1) is in settings1 then

set {theRegion, theCountry} to settings2

else

set {theRegion, theCountry} to settings1

end if

tell pop up button "Region:" of group 1

delay 0.25


click


clickmenu itemtheRegion of menu 1


clickmenu itemtheCountry of menu 1 of menu itemtheRegion of menu 1

end tell

if theCountry is in settings2 then

click button "Advanced…"

delay 0.25

tell tab group 1 of sheet 1

click pop up button "Currency:"

keystroke "Euro" & return & return

delay 0.25

end tell

end if

click button "Advanced…"

delay 0.25

tell tab group 1 of sheet 1


clickradio button "dates"

delay 0.25


keystroketab


keystroke "a" usingcommand down


set the clipboard to "dd.MM.y"


keystroke "v" usingcommand down

delay 0.25


keystrokereturn


keystroke "w" using {command down}

end tell

end tell

end tell

end tell



This seems to work more or less except that I've obviously messed up the If / then sequence. The script seems to work the way I want, but only some of the time! Can you put me right?


Thanks in advance (again),


Steve

Reply

Jun 3, 2015 6:12 AM in response to MucSteve

Something weird happened there. I'm not sure why it suddenly indented my code wrongly. I'll try posting it here as a screen shot:


User uploaded file

Just in case it wasn't clear, I should point out that I want the dot delimiter both in the German and the UK locales.

Reply

Jun 3, 2015 3:36 PM in response to MucSteve

Hi Steve,


The issue stems from the fact that, in your last version of the script, the line

if (value of pop up button "Region:" of group 1) is in settings1 then

soon becomes

if "Germany (Custom)" is in {"Europe", "Germany"}then

Try this:

set settings1 to {"Europe", "Germany"}

set settings2 to {"Europe", "United Kingdom"}


tell application "System Preferences"

activate

set current pane to paneid "com.apple.Localization"

end tell


tell application "System Events"

tell process "System Preferences"

tell window "Language & Region"

get value of pop up button "Region:" of group 1

if (word 1 of result) is in settings1 then

set {theRegion, theCountry} to settings2

else

set {theRegion, theCountry} to settings1

end if

tell pop up button "Region:" of group 1

delay 0.25

click

clickmenu itemtheRegion of menu 1

clickmenu itemtheCountry of menu 1 of menu itemtheRegion of menu 1

end tell

clickbutton "Advanced…"

delay 0.25

tell tab group 1 of sheet 1

if theCountry is in settings2 then

clickpop up button "Currency:"

keystroke "Euro" & return

end if

clickradio button "Dates"

keystroke "a" usingcommand down

set the clipboard to "dd.MM.y"

keystroke "v" usingcommand down

delay 0.25

keystrokereturn

end tell

keystroke "w" using {command down}

end tell

end tell

end tell

Reply

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Toggle "Language & Region" Sys Prefs w/ Applescript

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