Set short date format in mac system preferences

Joined
Nov 2, 2016
Messages
1
Reaction score
0
Hi,


I need to set the date time format to short form using applescript (Mac 10.6 and later).

1. Click System Preferences -> Language & Text -> Formats

2. Set Region value to "United Kingdom"

3. Click Customize button (1st) and set the year 2016 to 16(2 digits) in short.

I don't know how to set the value 16 in the dialog window. The below code is change the year as static. I need to set the year from drop down list (Click 2016 and set select 16 from the list). If anyone knows pls let us know.




Code:

global theSettings
local versName

set osVersion to do shell script "sw_vers -productVersion"
set versList to my explode(".", osVersion)
if (count of versList) > 1 then
set versName to item 2 of versList as number
end if
setRegionValue(versName)

on setRegionValue(osVers)
tell application "System Preferences"
activate
get the name of every pane of application "System Preferences"
set the current pane to pane id "com.apple.Localization"
get the name of every anchor of pane id "com.apple.Localization"
if osVers ≥ 6 and osVers < 8 then
reveal anchor "Formats" of pane id "com.apple.Localization"
else if osVers ≥ 8 and osVers < 9 then
reveal anchor "Region" of pane id "com.apple.Localization"
else if osVers ≥ 9 then
else -- Other Versions
end if
end tell
tell application "System Events"
tell application process "System Preferences"
tell window 1
if osVers ≥ 6 and osVers < 9 then
set the theCountry to "United Kingdom"
tell pop up button 1 of tab group 1
set regionValue to value of item 1 as string
if (regionValue is not equal to theCountry) then
delay 0.25
try
click
click menu item theCountry of menu 1
end try
end if
end tell
else if osVers ≥ 9 then
set theSettings to {"Americas", "United Kingdom"}
tell pop up button 1 of group 1
set {theRegion, theCountry} to theSettings
set regionValue to value of item 1 as string
if (regionValue is not equal to theCountry) then
delay 0.25
try
click
click menu item theRegion of menu 1
click menu item theCountry of menu 1 of menu item theRegion of menu 1
end try
end if
end tell
else if osVers ≥ 9 then
else -- Other Versions
end if
end tell
end tell
tell application "System Events"
tell application process "System Preferences"
click button 4 of tab group 1 of window "Language & Text"
set dateValue to value of static text 4 of group 1 of tab group 1 of window "Language & Text"
set dateList to my explode("/", dateValue)
set yr to item 3 of dateList
if (count of yr) is equal to 4 then
set yr to characters 3 thru -1 of yr as string
set item 3 of dateList to yr
end if
set dateFrmt to my joinAList(dateList, "/")
tell static text 4 of group 1 of tab group 1 of window "Language & Text"
keystroke dateFrmt // Here i need to change the year format
keystroke tab
keystroke tab
keystroke tab
keystroke tab
keystroke tab
keystroke return
end tell
end tell
end tell

View attachment 2080
keystroke "w" using {command down}
quit application "System Preferences"
end tell

end setRegionValue
on explode(delimiter, input)
local delimiter, input, ASTID
set ASTID to AppleScript's text item delimiters
try
set AppleScript's text item delimiters to delimiter
set input to text items of input
set AppleScript's text item delimiters to ASTID
return input
on error eMsg number eNum
set AppleScript's text item delimiters to ASTID
error "Can't explode: " & eMsg number eNum
end try
end explode

on joinAList(theList, delim)
set newString to ""
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to delim
set newString to theList as string
set AppleScript's text item delimiters to oldDelims
return newString
end joinAList


 

Attachments

  • shortFormat.png
    shortFormat.png
    111.6 KB · Views: 364
Last edited:

Cory Cooper

Moderator
Joined
May 19, 2004
Messages
11,102
Reaction score
492
Hello and welcome.

Due to my very limited experience with AppleScript/Automator, I don't have any helpful suggestions. Maybe the folks over at MacScripter can lend a hand.

C
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top