I’ve googled around with no luck to find a way to use AS to generate ordinal day dates, i.e. 1st, 2nd, 3rd, 4th, up to 31st. I’d like to be able to enable a script with a keystroke for easy pasting of the current ordinal day into several ongoing documents.
I found a way to do generate ordinals via a php shell script, but does anyone have a native applescript method?
This handler by one of our moderators, Nigel Garvey, does it nicely with surprising brevity:
-- Append an English ordinal suffix to a number, returning the result as string.
on ordinalise(n)
set units to n mod 10
if (units > 3) or ((n - units) mod 100 is 10) or (units < 1) or (units mod 1 > 0) then return (n as string) & "th"
return (n as string) & item units of {"st", "nd", "rd"}
end ordinalise
ordinalise(22) --> "22nd"
If you prefer the American spelling, change ordinalise to ordinalize.
Visions of it now appearing all over the Internet with that name! :/ It would just beat a handler in one of my ScriptBuilders efforts:
on DateOfThisInstanceOfThisWeekdayBeforeOrAfterThisDate(d, w, i)
As it’s two years and a few days since kai suddenly fell off the radar, I’d like to dedicate this specially-composed version of ordinalise(n) to him:
-- Append an English ordinal suffix to a number, returning the result as string.
on ordinalise(n) (* Special "kai" edition. *)
tell n mod 10 to (n as string) & item (it * (((it < 4) and (it > 0) and ((n - it) mod 100 is not 10) and (it mod 1 is 0)) as integer) + 1) of {"th", "st", "nd", "rd"}
end ordinalise
ordinalise(22) --> "22nd"