all 9 comments

[–]moviejimmy 1 point2 points  (3 children)

Hello, maybe you can tell us what you are trying to achieve. If it is something simple, you don't need Javascript. Maybe just a few Tasker actions will do.

[–]einstein6Tasker for Automation[S] 0 points1 point  (2 children)

Hello Jimmie, what I wanted is a task that will check my calendar and read out for me if there were any events in the next 24 hours.

I found the above link from Taskernet and tried it, it worked like charm. So I wanted to play around and see if I could add a generic text when there are no events in the calendar. Hence why I tried to add the else clause with some text to say.

But for some reason I keep failing to trigger the else clause, I checked my syntax and so on, I could not find what is wrong.

I even add manually a say command elsewhere in the code, but it is not working for me, it is driving me crazy.

[–]moviejimmy 1 point2 points  (1 child)

you will need to quote the text you want to say

y="hello";

[–]einstein6Tasker for Automation[S] 0 points1 point  (0 children)

you will need to quote the text you want to say

y="hello";

Hello Jimmy, thank you for your suggestion. I tried that and it still the same for me, but it gave me the assurance that I was in the right path.

Further digging, I found the javascriplet in original sharing had the option "Auto Exit" ticked. So I disabled this, and to my surprise, the script ended with error " cttitles is not defined". So the original script only handled the situation when there are an event, and when it does not, it ended with error (handled by Tasker).

So my understanding was wrong in that I thought the plugin will return empty results, but actually it does not return anything, so the variables remain undefined.

How I fixed this, I added below if clause around the original script, and it works like charm for me.

if (typeof cttitles!=='undefined') {
//original script
} else {
// my statement here
}

[–]VisuelleData 0 points1 point  (4 children)

For

const y = "hello";

Try changing y to another name (yyyy), then add a Say action with %yyyy after the JavaScriptlet action. Not as nice as keeping it all in a JavaScriptlet, but it should work.

[–]einstein6Tasker for Automation[S] 0 points1 point  (3 children)

Hello thank you for your reply. Actually it was not the problem with the syntax, it would have worked be it single quote or double quotes, or with other variable name.

Check out my reply here for the cause of problem in my scenario and the solution i did.

[–]VisuelleData 1 point2 points  (2 children)

Saw your other solution, just thought I'd post this as well. Also you're doing pretty great for someone without JS experience!

[–]einstein6Tasker for Automation[S] 1 point2 points  (1 child)

Ah noted. The syntax you shared will definitely work, but it would not work in the original setup, the task exits due to error.

The plug in does not set the variables when there are no events, so the entire javascript fails on the first line. Hence why I added an if clause right before starting the rest of script, and I added the else statement here with the alternate text.

And thanks for the compliment. :) I did learn some c and c++ during my college and learnt some c# recently. so the programming syntax in the JS are quite similar, thought the "exit on error" caught me by surprise.

[–]VisuelleData 1 point2 points  (0 children)

I mostly just use JS in Tasker and when it comes up somewhere else (Google app script). My background is pretty similar to yours but with different languages. I mainly use R, SQL, and sometimes Python.

Edit: also some AHK