Names of all installed applications.kmmacros (3.3 KB)
Expand disclosure triangle to view JS Source
(() => {
"use strict";
ObjC.import("AppKit");
// ----- MACOS LISTING OF INSTALLED APPLICATIONS -----
// RobTrew @2022
// Ver 0.01
// main :: IO ()
const main = () =>
lines(
Object.assign(
Application.currentApplication(),
{includeStandardAdditions: true}
)
.doShellScript("pkgutil --pkgs")
)
.flatMap(bundleID => {
const
fp = ObjC.unwrap(
$.NSWorkspace.sharedWorkspace
.URLForApplicationWithBundleIdentifier(
bundleID
)
.fileSystemRepresentation
);
return Boolean(fp) ? (
[takeBaseName(fp)]
) : [];
})
.sort()
.join("\n");
// --------------------- GENERIC ---------------------
// lines :: String -> [String]
const lines = s =>
// A list of strings derived from a single string
// which is delimited by \n or by \r\n or \r.
Boolean(s.length) ? (
s.split(/\r\n|\n|\r/u)
) : [];
// takeBaseName :: FilePath -> String
const takeBaseName = fp =>
// The filepath without any extension.
("" !== fp) ? (
("/" !== fp[fp.length - 1]) ? (() => {
const fn = fp.split("/").slice(-1)[0];
return fn.includes(".") ? (
fn.split(".").slice(0, -1)
.join(".")
) : fn;
})() : ""
) : "";
// MAIN ---
return main();
})();