Does anyone have a macro for pulling the "date created" data of a file from the contextual menu that appears when right-clicking on it and selecting "get info?"
See the Get File Attribute action.
Although there seems to be a bug with it in KM10 preventing the action from using a text token or tokenized variable.
It also returns a Unix date, which you have to convert to get a human readable date
Be more specific about what you want.
- The creation date of an item selected in the Finder?
- Or what?
-Chris
Yes, the item selected in the Finder.
And here is a JS route to listing the creation dates of several selected files.
Creation dates of any files selected in Finder.kmmacros (5.6 KB)
Expand disclosure triangle to view JS Source
(() => {
"use strict";
// Creation dates of any files selected in Finder
// Ver 0.02
// Rob Trew @ 2021
// main :: IO ()
const main = () =>
(Application("Finder").selection() || [])
.flatMap(x => {
const
fp = decodeURI(x.url()).slice(7),
fileName = takeFileName(fp);
return [
either(
message => `${fileName} :: ${message}`
)(
status => {
const created = taskPaperDateString(
status.NSFileCreationDate
);
return `${created} :: ${fileName}`;
}
)(
fileStatus(fp)
)
];
})
.sort()
.join("\n") || "Nothing selected in Finder.";
// --------------------- GENERIC ---------------------
// Left :: a -> Either a b
const Left = x => ({
type: "Either",
Left: x
});
// Right :: b -> Either a b
const Right = x => ({
type: "Either",
Right: x
});
// either :: (a -> c) -> (b -> c) -> Either a b -> c
const either = fl =>
// Application of the function fl to the
// contents of any Left value in e, or
// the application of fr to its Right value.
fr => e => e.Left ? (
fl(e.Left)
) : fr(e.Right);
// fileStatus :: FilePath -> Either String Dict
const fileStatus = fp => {
const
e = $(),
dct = $.NSFileManager.defaultManager
.attributesOfItemAtPathError(
ObjC.wrap(fp).stringByStandardizingPath,
e
);
return dct.isNil() ? (
Left(ObjC.unwrap(e.localizedDescription))
) : Right(ObjC.deepUnwrap(dct));
};
// iso8601Local :: Date -> String
const iso8601Local = dte =>
new Date(dte - (6E4 * dte.getTimezoneOffset()))
.toISOString();
// taskPaperDateString :: Date -> String
const taskPaperDateString = dte => {
const [d, t] = iso8601Local(dte).split("T");
return [d, t.slice(0, 5)].join(" ");
};
// takeFileName :: FilePath -> FilePath
const takeFileName = fp =>
// The file name component of a filepath.
"" !== fp ? (
"/" !== fp[fp.length - 1] ? (
fp.split("/").slice(-1)[0]
) : ""
) : "";
// MAIN ---
return main();
})();
The other answers that were given to you are the correct answers. However I'm going to give you an alternate answer because I'm so enamoured with Monterey's OCR. This solution requires that you have a Monterey shortcut called OCRrectangle which I documented in another post. This solution hasn't failed me yet, even though in theory it might be less reliable. But it works! If you really want to, you can use this weird solution, or just examine it for its entertainment value.
I'm going to post only a screenshot of the code because it has a hardcoded path and requires a Monterey shortcut so posting the macro itself isn't very helpful.
I made the KM window as small as possible for inserting this screenshot. I think the reason it looks "big" is because I'm using a rather large-font screen resolution on a high res screen. I don't really want to change my screen resolution every time I post an answer.