I found there is new trigger "After BetterTouchTool did Launch / Start on Mac with Serial Number" appeared recently, I never created or imported before, what is used for? Why appeared? Can I delete it?
When triggered the action will run a JS:
async function createAppCache() {
let filePaths = await runShellScript({
// this will search the typical app folders
script: `mdfind -onlyin ~/Applications -onlyin /Applications -onlyin /System/Applications 'kMDItemFSName == "*.app"'`,
});
// Split the file paths by new line
let fileArray = filePaths.split("\n").filter(Boolean); // filter(Boolean) removes any empty lines
// Create an array of objects with filePath and fileName
let files = fileArray.map((filePath) => {
let fileName = filePath.split("/").pop(); // Extract the file name from the path
return { filePath, fileName };
});
let menuItems = [];
// Function to retrieve the icon path by reading the Info.plist
async function getAppIconPath(filePath) {
// Construct the path to the Info.plist file
let plistPath = `${filePath}/Contents/Info.plist`;
// Run a shell script to retrieve the CFBundleIconFile from the Info.plist
let iconName = await runShellScript({
script: `defaults read "${plistPath}" CFBundleIconFile || echo "AppIcon"`,
});
// Add the .icns extension if not present
iconName = iconName.trim();
if (!iconName.endsWith(".icns")) {
iconName += ".icns";
}
// Return the full path to the .icns file
return `${filePath}/Contents/Resources/${iconName}`;
}
// Create the list menu items that trigger a shell script to open the app
for (let file of files) {
let iconPath = await getAppIconPath(file.filePath); // Get the correct icon path from Info.plist
let item = {
title: file.fileName,
action: `js::(async () => {runShellScript({script: 'open "${file.filePath}"'})})()`,
icon: `path::${iconPath}::width@@30`,
};
menuItems.push(item);
}
// add finder manually because it's in an unusal location
menuItems.push({
title: "Finder",
action: `js::(async () => {runShellScript({script: 'open "/System/Library/CoreServices/Finder.app"'})})()`,
icon: `path::/System/Library/CoreServices/Finder.app/Contents/Resources/Finder.icns::width@@30`,
});
// write to the cache file
return writeStringToFile(
JSON.stringify(menuItems),
"~/Library/Application Support/BetterTouchTool/app-cache.json"
);
}