Is there a way to change the date and time format without changing the Region in macOS preferences?
I use English as the primary Language & Region, but want to be able to switch to Swedish occasionally, to show days and months in that language using date and time macros.
I’ve seen some solutions using Terminal, but that involves a restart, and I want to be able to switch back and forth between languages quickly.
If I understand you correctly you just want to perform some date math - right ?!
If that’s the case I can use the Offset time in a calculation with variables and manipulate the output string of KM‘s date and time Tokens to get the desired result.
I have no chance getting to my Mac because I am not at home but I hope this may help you
Thanks Tobias!
I just want to be able to choose language, English or Swedish, for the output.
For example:
Tuesday, 20 February 2024
vs
Tisdag, 20 Februari 2024
With an example like yours, where there are so few search terms, it can at the very least be brute forced by translation, setting it up as a Search and replace within a For each, like this:
and another approach is to experiment with passing different two-character locale strings like {"sw" "fr" "zh" "he" "en"}
drawn from (List of ISO 639 language codes - Wikipedia)
to Apple Foundation Class methods through a Keyboard Maestro Execute JavaScript for Automation action:
I tried your string: (2023-03-06 14:35), and I got: ”3 Machi 5877521 -596:-31”.
Found out that ”sw” is language code for Swahili.
swe or sv is Swedish.
Now Date works, but there’s still problems with Time, so I have to try some more when I get the time.
Afterthought: for some purposes it may be simpler to use Keyboard Maestro's TIME() function in (in a Calculate action, or a Calculate Token) to supply Unix Epoch seconds as a digit string.
TIME() alone for 'now'
or with more detail, like TIME(1911, 2, 23)
You can submit those digits, parsed as a JS Number(), in a pattern like this:
(() => {
"use strict";
// Sample for testing:
// These values can be made available, with their
// kmvar. prefix, in the drop-down menu behind the
// small chevron at the left of a KM11 Execute
// JavaScript for Automation action.
const kmvar = {
"local_UnixTimeDigits": Application(
"Keyboard Maestro Engine"
)
.calculate("TIME()"),
"local_shortLocaleName": "sv"
};
const nsDateFormatter = $.NSDateFormatter.alloc.init;
nsDateFormatter.setDateStyle(
$.NSDateFormatterLongStyle
);
nsDateFormatter.setTimeStyle(
$.NSDateFormatterNoStyle
);
nsDateFormatter.setLocale(
$.NSLocale.alloc.initWithLocaleIdentifier(
kmvar.local_shortLocaleName
)
);
return ObjC.unwrap(
nsDateFormatter.stringFromDate(
$.NSDate.alloc.initWithTimeIntervalSince1970(
Number(kmvar.local_UnixTimeDigits)
)
)
);
})();