# Convert todays date to Roman Numerals

This is a little Macro to convert todays day into Roman Numerals, Sample...

**

## Convert year into Roman Numerals script:

**

tell application "Keyboard Maestro Engine"
set kmVarRef to make variable with properties {name:"Year_km"}
set n to value of kmVarRef
--¸set value of kmVarRef to 10
end tell

try
--set n to 2015
if (n as integer) > 3999 then error "Max number is 3999" number 1
set r to ""
repeat with i from 1 to (count (n as string))
set r to item (((item -i of (n as string)) as integer) + 1) of item i of ¬
{{"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"}, ¬
{"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"}, ¬
{"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"}, ¬
{"", "M", "MM", "MMM"}} & r
end repeat
return r
on error eMsg number eNum
error display dialog "Year out of range Try Again" with icon caution
end try

**

## Convert month into Roman Numerals script:

**

tell application "Keyboard Maestro Engine"
set kmVarRef to make variable with properties {name:"Month_km"}
set n to value of kmVarRef
end tell
set MonthList to {"I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XII", "XII"}
set TheMonth to item n of MonthList
return TheMonth

**

## Convert day into Roman Numerals script:

**

tell application "Keyboard Maestro Engine"
set kmVarRef to make variable with properties {name:"Day_km"}
set n to value of kmVarRef
end tell
set DayList to {"I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI", "XII", "XIII", "XIV", "XV", "XVI", "XVII", "XVIII", "XIX", "XX", "XXI", "XXII", "XXXII", "XXIV", "XXV", "XXVI", "XXVII", "XXVIII", "XXIX", "XXX", "XXXI"}
set TheDay to item n of DayList
return TheDay

## Here is the source macro..

Enjoy...

BTW.. I'm a newbie so I'm asking to be easy on me.. LOL..
Also I see after posting I noticed unnecessary remarks in the script... can be removed.. Sorry..
I'm tiered.. LOL..

William (Bill)

1 Like

Very good to see that classical culture is still very much alive and kicking : - )

Perhaps this contains material for further macro projects ?

Calendrical calculations

1 Like

LOL…
I use the roman numerals with © to stamp my digital art work it gives a nice look…

2 Likes

Hey Bill,

A good learning exercise.

But since you’re doing all the heavy-lifting in AppleScript let’s simplify just a bit:

``````try

tell (current date)
set yearInt to its year
set monthInt to its month as integer
set dayInt to its day
end tell
set RomanYear to ""
repeat with i from 1 to (count (yearInt as string))
set RomanYear to item (((item -i of (yearInt as string)) as integer) + 1) of item i of ¬
{{"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"}, ¬
{"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"}, ¬
{"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"}, ¬
{"", "M", "MM", "MMM"}} & RomanYear
end repeat
set RomanMonth to item monthInt of {"I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XII", "XII"}
set RomanDay to item dayInt of {"I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI", "XII", "XIII", "XIV", "XV", "XVI", "XVII", "XVIII", "XIX", "XX", "XXI", "XXII", "XXXII", "XXIV", "XXV", "XXVI", "XXVII", "XXVIII", "XXIX", "XXX", "XXXI"}
set the clipboard to RomanDay & "-" & RomanMonth & "-" & RomanYear

on error e number n
set e to e & return & return & "Num: " & n
if n ≠ -128 then
try
tell current application to button returned of ¬
(display dialog e with title "ERROR!" buttons {"Copy Error Message", "Cancel", "OK"} ¬
default button "OK" giving up after 30)
if ddButton = "Copy" then set the clipboard to e
end try
end if
end try
``````

This requires only one ‘Execute AppleScript Action’, and the AppleScript itself will set the clipboard.

Of course this is only for today’s date (current date).

If you want to be able to enter a custom date you can add some code similar to this to the beginning of the script:

``````try

tell (current date)
set yearInt to its year
set monthInt to its month as integer
set dayInt to its day
end tell

set defaultDateString to (yearInt & "/" & monthInt & "/" & dayInt) as text

tell current application
set userDateString to text returned of (display dialog "Enter a date of the form: YYYY/MM/DD" default answer defaultDateString as text)
end tell

if userDateString ≠ defaultDateString then
set AppleScript's text item delimiters to "/"
set {yearInt, monthInt, dayInt} to text items of userDateString
end if

on error e number n
set e to e & return & return & "Num: " & n
if n ≠ -128 then
try
tell current application to button returned of ¬
(display dialog e with title "ERROR!" buttons {"Copy Error Message", "Cancel", "OK"} ¬
default button "OK" giving up after 30)
if ddButton = "Copy" then set the clipboard to e
end try
end if
end try
``````

You can also use the ‘Prompt for User Input’ to use KM instead of AppleScript to ask the user for a custom date string, but I won’t get into that at the moment.

-Chris

1 Like

This is wonderful
I could really use this and I will take a good look at this script “dissect it” how it works.
Thank you a million and understanding and experience your are very kind.

I’m looking for a site that will help me understand applescript “AppleScript for Dummies” LOL…
I have been avoiding applescript for years and now I have time on my hands I think it’s time…

Agin Thank you Chris

FWIW a JSC Javascript variant, which should work in earlier versions of OS X, as well as in Yosemite:

(Updated to rewrite multiple numbers, preserving any separator)

(JSC is the generic Javascript engine in OSX - it doesn't do osascript automation, but the standard Javascript libraries are all there, and accessible to `Execute Script` actions in KM)