Insert date in spanish OR find and replace english text with spanish

Howdy all. I have a string that inserts the date and time into a long script (I do telephonic legal interpreting, so I have a variety of scripts I have to read along with date and time), but I would like to have it enter it in spanish.

Barring that, I would like to be able to have it search and replace the english terms with the corresponding spanish terms.

For instance, my string would insert "Estamos grabando la audiencia el Wednesday, July 04, 2018 aproximadamente a las 04:20 PM.", but I would like to either have it insert the day and month in spanish, or replace those with the spanish terms.

I haven't found a way of doing this unfortunately. I tried using image found and screenshotting the actual words followed by clicking and inserting the replacement text but that's really complicated and doesn't work reliably. The only search and replace function I have found has to do with the Clipboard, and not a window. I haven't found ANYTHING about ICU date/time formatting in spanish.

Any ideas?

Keyboard Maestro’s text tokens can insert the date in your localised format, but if that is not Spanish, then Keyboard Maestro has no direct help for you.

There might be scripts you could use to get the localised time/date in Spanish (I am sure it could be done with JXA), maybe with the date command.

Yes, indeed the date command will do the trick, specifying a Spanish locale, and an appropriate format (as described by the strftime man page.

Execute a Shell Script.kmactions (690 B)

3 Likes

This is fantastic! With the regular ICU date/time format I know how to modify the time string to offset for other time zones (for instance I'm in MST but a lot of my calls come from PST), is there a way to do this with your script? I've tried a few things but haven't had success.

Here's how I get local time in Italy using Peter's solution:

TZ=":Europe/Madrid" should do it for Spain or TZ=":America/Mexico_City" for Mexico.

1 Like

Awesome! I replaced "Mexico_City" with "Tijuana" and it worked.

Is there a way to look up other cities?

I tried ones like "San_Francisco", "Dallas" etc. but it kept giving me the wrong time.

All the cities are in folders for the areas in /usr/share/zoneinfo so if you look in /usr/share/zoneinfo/America you'll find:

Adak		Coral_Harbour	Havana		Miquelon	Rosario
Anchorage	Cordoba		Hermosillo	Moncton		Santa_Isabel
Anguilla	Costa_Rica	Indiana		Monterrey	Santarem
Antigua		Creston		Indianapolis	Montevideo	Santiago
Araguaina	Cuiaba		Inuvik		Montreal	Santo_Domingo
Argentina	Curacao		Iqaluit		Montserrat	Sao_Paulo
Aruba		Danmarkshavn	Jamaica		Nassau		Scoresbysund
Asuncion	Dawson		Jujuy		New_York	Shiprock
Atikokan	Dawson_Creek	Juneau		Nipigon		Sitka
Atka		Denver		Kentucky	Nome		St_Barthelemy
Bahia		Detroit		Knox_IN		Noronha		St_Johns
Bahia_Banderas	Dominica	Kralendijk	North_Dakota	St_Kitts
Barbados	Edmonton	La_Paz		Ojinaga		St_Lucia
Belem		Eirunepe	Lima		Panama		St_Thomas
Belize		El_Salvador	Los_Angeles	Pangnirtung	St_Vincent
Blanc-Sablon	Ensenada	Louisville	Paramaribo	Swift_Current
Boa_Vista	Fort_Nelson	Lower_Princes	Phoenix		Tegucigalpa
Bogota		Fort_Wayne	Maceio		Port-au-Prince	Thule
Boise		Fortaleza	Managua		Port_of_Spain	Thunder_Bay
Buenos_Aires	Glace_Bay	Manaus		Porto_Acre	Tijuana
Cambridge_Bay	Godthab		Marigot		Porto_Velho	Toronto
Campo_Grande	Goose_Bay	Martinique	Puerto_Rico	Tortola
Cancun		Grand_Turk	Matamoros	Punta_Arenas	Vancouver
Caracas		Grenada		Mazatlan	Rainy_River	Virgin
Catamarca	Guadeloupe	Mendoza		Rankin_Inlet	Whitehorse
Cayenne		Guatemala	Menominee	Recife		Winnipeg
Cayman		Guayaquil	Merida		Regina		Yakutat
Chicago		Guyana		Metlakatla	Resolute	Yellowknife
Chihuahua	Halifax		Mexico_City	Rio_Branco
1 Like

That's just what I needed, thanks so much!