Hey guys, I'm trying to use the Trello's API to get a task on my touchbar. I have the API setup but how can I setup a js http request on the BTT?
Is that the correct way? Is there another way around?
Thanks
Hey guys, I'm trying to use the Trello's API to get a task on my touchbar. I have the API setup but how can I setup a js http request on the BTT?
Is that the correct way? Is there another way around?
Thanks
I'm not familiar with js, but you can use applescript to achieve HTTP request.
see: https://stackoverflow.com/questions/8119487/applescript-simple-get-request
Hey thanks but I'm having this error:
ReferenceError: Can't find variable: fetch
you need to select „real javascript“ - the javascript for automation won’t work because it’s only a Apple subset of JS
@Andreas_Hegenberg I'm actually having the same problem. I'm definitely using the "Real Javascript" option, but any call to fetch crashes with "Can't find variable "fetch"".
Here's my code:
Clicking "Run Script" just outputs: ReferenceError: Can't find variable: fetch
Running this code in Node directly works great, but this fails for some reason.
Are you maybe on an older version of macOS that doesn't support fetch yet? (I have only tested on Catalina)
Hey Andreas yes, I'm running Catalina version 10.15.3
Apparently the standard JavaScript environment on macOS indeed doesn't come with fetch support. (It wasn't throwing that error message on my machine because of some debug settings).
I will add support for fetch (or something similar) today or tomorrow and upload a new alpha build.
That's amazing! Thanks man
string.indexOf() and list.ForEach() is also needed ~ ~
@Noon_Chen here are definitely included in the standard macOS JavaScript and work fine in BTT (at least on Catalina):
In v3.347 alpha I added a basic fetch implementation (it doesn't cover the whole fetch API, but maybe it will work for your use cases). Please let me know. (It's unfortunate having to reimplement this, but there seems to be no way to access the standard Apple fetch implementation)
let web_list = ["url1", "url2" ]; //a list of strings
let activeURL = runAppleScript(
`tell application "Google Chrome" to set currTab to URL of active tab of front window
return currTab`);
//let result = web_list.ForEach((v)=>{if(activeURL.indexOf(v)!=-1){return "Found"}else{return ""}});
//TypeError: web_list.ForEach is not a function. (In 'web_list.ForEach((v)=>{if(activeURL.indexOf(v)!=-1){return "Found"}else{return ""}})', 'web_list.ForEach' is undefined)
var match = false
for (i=0; i<web_list.length; i++){
if (activeURL.indexOf(web_list[i])!=-1){var match = true;break;}
//TypeError: activeURL.indexOf is not a function. (In 'activeURL.indexOf(web_list[i])', 'activeURL.indexOf' is undefined)
}
returnToBTT(match);
@Andreas_Hegenberg I'm a js newbie, I really don't know why does it not work for me...
it’s forEach (casing!).
Also you should check whether activeURL is actually set before calling indexOf
if(activeURL) {
// do something
}
well, just like you mentioned, runAppleScript doesn't return a string but a [object Promise]? I tried to put the code inside of (async ()=> {//code in here...})(), but BTT crashed😂
It should be something like this:
(async () => {
let web_list = ["url1", "url2" ]; //a list of strings
let activeURL = await runAppleScript(
`tell application "Google Chrome" to set currTab to URL of active tab of front window
return currTab`);
var match = false
if(activeURL) {
//let result = web_list.ForEach((v)=>{if(activeURL.indexOf(v)!=-1){return "Found"}else{return ""}});
//TypeError: web_list.forEach is not a function. (In 'web_list.ForEach((v)=>{if(activeURL.indexOf(v)!=-1){return "Found"}else{return ""}})', 'web_list.ForEach' is undefined)
for (i=0; i<web_list.length; i++){
if (activeURL.indexOf(web_list[i])!=-1){var match = true;break;}
//TypeError: activeURL.indexOf is not a function. (In 'activeURL.indexOf(web_list[i])', 'activeURL.indexOf' is undefined)
}
}
returnToBTT(match);
})()
Hey @Andreas_Hegenberg thank you bud! I'll wait for the release to test it.
Have a good one!
it's already released (click "check for alpha version updates")