Crypto-Touchbar-App
Crypto-Touchbar-App copied to clipboard
Python 2.x removed from macOS 12.3, migrate to Java Script?
Now that Apple has removed Python from the macOS 12.3 betas, it might make sense to switch the templates to use Java Script widgets - so no third party binaries are needed.
I'm opening this issue to discuss whether this makes sense :-)
I did a quick proof of concept script that seems to work fine, but it currently lacks any customization options apart from the coins and the currencies:
// BTT doesn't support top level await, thus needs to be wrapped in a self executing function
(async () => {
const coinsToLoad = ["BTC"];
const currenciesToLoad = ["EUR"];
async function fetchCrypto(coins, currencies) {
const fsyms = coins.join(",");
const tsyms = currencies.join(",");
const cryptoCompareURL = `https://min-api.cryptocompare.com/data/pricemultifull?fsyms=${fsyms}&tsyms=${tsyms}`;
const response = await fetch(cryptoCompareURL);
const json = await response.json();
const currentPrices = [];
for (const currency of currencies) {
for (const coin of coins) {
currentPrices.push(json["RAW"][coin][currency]["PRICE"] + " " + currency);
}
}
return currentPrices;
}
const resultPrices = await fetchCrypto(coinsToLoad, currenciesToLoad);
returnToBTT(resultPrices.join(" | "));
})();

I will add a readFile and writeFile function to the BTT Java Script runner, so the cache can also be implemented.
Hey, appreciate the heads up - I had no idea that had been removed. To be honest seems like a good enough reason as any to remove the python dependency.
Just to be clear the JS runs inside BTT so a user wouldn't need any nodejs installed etc?
Is there any version/limitations/spec/comparison on what's allowed inside the JS inside BTT?
yes it runs inside of BTT using the javascript core framework from Apple, it's available starting with 3.333 http://docs.folivora.ai/docs/1106_java_script.html
(maybe having a switch to keep python for older versions makes sense, but 3.333 was also released more than a year ago )
If we use the set_persistent_string_variable we also don't need a file based cache.