Set short date format in mac system preferences

Discussion in 'AppleScript' started by Sudha, Nov 2, 2016.

  1. Sudha

    Sudha New Member

    Joined:
    Nov 2, 2016
    Messages:
    1
    Likes Received:
    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


     

    Attached Files:

    Last edited: Nov 2, 2016
    Sudha, Nov 2, 2016
    #1
    1. Advertisements

  2. Sudha

    Cory Cooper Moderator

    Joined:
    May 19, 2004
    Messages:
    4,742
    Likes Received:
    128
    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
     
    Cory Cooper, Nov 5, 2016
    #2
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. Alice Faber
    Replies:
    1
    Views:
    985
    Brad Ackerman
    Apr 5, 2004
  2. Mirsky
    Replies:
    10
    Views:
    271
    Michelle Steiner
    May 29, 2008
  3. Stuart Bell
    Replies:
    7
    Views:
    442
    Sak Wathanasin
    Oct 21, 2003
  4. Tim Arnfield
    Replies:
    4
    Views:
    593
    Jon B
    Mar 24, 2005
  5. Ian McCall

    MobileMe Mail: set UK date format?

    Ian McCall, Aug 31, 2008, in forum: UK Macs
    Replies:
    8
    Views:
    189
    Andy Hewitt
    Aug 31, 2008
  6. Muvuth
    Replies:
    1
    Views:
    304
    Cory Cooper
    Sep 4, 2016
  7. UserUser
    Replies:
    6
    Views:
    391
    UserUser
    Sep 22, 2016
  8. Muzzatow
    Replies:
    4
    Views:
    379
    Muzzatow
    Sep 23, 2016
Loading...