Puede usar NSDataDetector ( un método de cacao ) para analizar la fecha de una cadena.
Aquí está el script (probado en macOS Sierra ):
Advertencia: en una cadena que contiene " dígito / dígito / año ", el script no funciona con una cadena en el " día / mes / año ", la cadena debe estar en el formato" mes / día / año "
use framework "Foundation"
use scripting additions
(* this script works on these formats:
"Sunday 10th September 2017", "Sunday 10 September 2017", "Sunday 10 September 17", "September 10th, 2017", "September 10th 2017", "September 10 2017"
"10th September 2017", "10 September 2017", "10 Sep 17"
also work with the abbreviation ( e.g. Sep instead of September and Sun instead of Sunday)
also work with the localized name of (the month and the day)
"09/10/2017", "09.10.2017", "09-10-2017" : month_day_year only, or "2016/05/22", "2016-05-22", "2016.05.22" : year_month_day only
( month and days could be one or two digits)
*)
set myString to "Nov 5th, 2005"
set dateString to my stringToDate(myString) --> "05/11/2005"
on stringToDate(thisString) --
tell current application
-- ** finds all the matches for a date, the result is a NSArray **
set m to its ((NSDataDetector's dataDetectorWithTypes:(its NSTextCheckingTypeDate) |error|:(missing value))'s matchesInString:thisString options:0 range:{0, length of thisString})
if (count m) > 0 then
set d to (item 1 of m)'s |date|() -- get the NSDate of the first item
set df to its NSDateFormatter's new() -- create a NSDateFormatter
df's setDateFormat:"dd/MM/yyyy" -- a specified output format: "day/month/year" (day and month = two digits, year = 4 digits)
return (df's stringFromDate:d) as text
end if
end tell
return "" -- no match in this string
end stringToDate