• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Accessing UserDefaults via vanilla AS?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Accessing UserDefaults via vanilla AS?


  • Subject: Re: Accessing UserDefaults via vanilla AS?
  • From: Nigel Garvey <email@hidden>
  • Date: Wed, 23 Apr 2003 12:46:59 +0100

Jeff Ganyard wrote on Tue, 22 Apr 2003 17:35:05 -0700:

>Hi All,
>
>I'm looking for the fastest vanilla way to get the value of
>NSDateFormatString from the .GlobalPreferences.plist

set globalPrefs to (path to preferences from user domain as string) &
".GlobalPreferences.plist"
set fRef to open for access file globalPrefs
try
set prefText to read fRef
end try
close access fRef

set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to
{"<key>NSDateFormatString</key>" & (ASCII character 10)}
set formatStr to paragraph 1 of text item 2 of prefText
set AppleScript's text item delimiters to astid
set formatStr to text 10 thru ((offset of "</" in formatStr) - 1) of
formatStr

--> "%A, %B %e, %Y" ("U.K.")
--> "%d de %B de %Y" (Brazil)

"%A" = weekday; "%B" = month; "%d" = day with leading zero; "%e" = day
without leading zero; "%Y" = year.

(I've put "U.K" in inverted commas to emphasise that it's the system
preset called "U.K.", not a date format used by anyone in the United
Kingdom.)

>Or if there's some other way to 'discover' the user defined Date
>format, I would be most appreciative!

If you know the language being used, you could parse the 'date string' of
a date of your choosing.

For short dates, the heading in ".GlobalPreferences.plist" is
"NSShortDateFormatString". But if you're only interested in the user's
preferred short-date order, and mean to impose your own ideas on
separators, leading zeros, and centuries, this is convenient:

set {day:d, year:y} to date ("1/2/3" as string) -- resolve at run time
only
set y to y mod 100

tell {missing value, missing value, missing value}
set (item d, item y, item (6 - d - y)} to {"dd", "yy", "mm"}
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"/"}
set sDateOrder to it as string
set AppleScript's text item delimiters to astid
end tell

sDateOrder

NG
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Accessing UserDefaults via vanilla AS?
  • Next by Date: Re: List view properties
  • Previous by thread: Re: Accessing UserDefaults via vanilla AS?
  • Next by thread: Re: Accessing UserDefaults via vanilla AS?
  • Index(es):
    • Date
    • Thread