assigning (good) morning, afternoon & evening greeting from Tasker

294 views
Skip to first unread message

Logan Fury

unread,
Jan 25, 2017, 2:34:41 AM1/25/17
to Tasker
Hello, 

I wanted to get a task that would adjust greeting based on time of day, but couldnt google anything close except for what appeared to be webpage script at a javasource. Ive got the relevant (edited) part here:


<script language="JavaScript"> 
var myDate = new Date(); 
  
/* hour is before noon */
if ( myDate.getHours() < 12 )  
    document.write("Good Morning!"); 
else  /* Hour is from noon to 4pm (actually to 4:59 pm) */
if ( myDate.getHours() >= 12 && myDate.getHours() <= 16 ) 
    document.write("Good Afternoon!"); 
else  /* the hour is after 4pm, so it is between 5pm and midnight */
if ( myDate.getHours() > 16 && myDate.getHours() <= 24 ) 
    document.write("Good Evening!"); 
else  /* the hour is not between 0 and 24, so something is wrong */
    document.write("I'm not sure what time it is!"); 

</script> 

is there a way to incorporate an edit of this (im sure this isnt formated for Tasker) into the Tasker JavaScriptlet, and create a variable called 

%greet

or 

%hello

or anything applicable so that I can have tasks that seem cognizant of the time of day please?

This isnt something I can just edit with a few subtle hints, unfortunately im not a Coder. Has anyone time to walk me thru "Taskerizing" this script and then making use of its output?

Thank you very much,

Logan

Brian Wilson

unread,
Jan 25, 2017, 8:35:55 AM1/25/17
to Tasker
I call this task to get the time of day, which can then be incorporated into a response our used as a context in a different task:

[Code]
Get Time Period (117) <Get time of day> A1: If [ %TIME < 12 ]
A2: Variable Set [ Name:%timeperiod To:morning Recurse Variables:Off Do Maths:Off Append:Off ]
A3: Else If [ %TIME < 18 ]
A4: Variable Set [ Name:%timeperiod To:afternoon Recurse Variables:Off Do Maths:Off Append:Off ]
A5: Else
A6: Variable Set [ Name:%timeperiod To:evening Recurse Variables:Off Do Maths:Off Append:Off ]
A7: End If
A8: Return [ Value:%timeperiod Stop:On ]
[/code]

Logan Fury

unread,
Jan 25, 2017, 10:36:50 AM1/25/17
to tas...@googlegroups.com
Good Morning Brian,

Thank you very much for the reply!

I made your above code verbatim into its own task (although I set evening back from 6pm to 5pm via TIME < 17)

I then tried a two task profile:

A1 Perform Task Get Time Peroid
A2 Alert Say %timeperoid Logan

This is giving a return of the phone speaking out "percent tee, eye, emm....."

instead of the proper good morning/afternoon/evening I expected.

Am I missing a step? I have made sure to back completely out of Tasker and rebooted phone since adding this data.


--
You received this message because you are subscribed to a topic in the Google Groups "Tasker" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tasker/06WUs_Q55Zc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tasker+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/tasker.
For more options, visit https://groups.google.com/d/optout.

Logan Fury

unread,
Jan 25, 2017, 10:46:43 AM1/25/17
to tas...@googlegroups.com
Does this perhaps need to be turned into a global variable before I can use its into in other profiles/tasks and does that take additional steps/code?

Scott

unread,
Jan 25, 2017, 1:50:01 PM1/25/17
to Tasker
In your A1 task are you setting the return variable to %timeperiod?
To unsubscribe from this group and all its topics, send an email to tasker+un...@googlegroups.com.

Logan Fury

unread,
Jan 25, 2017, 4:20:35 PM1/25/17
to tas...@googlegroups.com
Hello Scott,

I dont know how to set that variable in A1. Here is the 2 tasks I have:

Get Time Peroid

Get Time Peroid (146)
A1: If [ %TIME < 12 ]
A2: Variable Set [ Name:%timeperoid To:morning Recurse Variables:Off Do Maths:Off Append:Off ] 
A3: Else If [ %TIME < 17 ]
A4: Variable Set [ Name:%timeperoid To:afternoon Recurse Variables:Off Do Maths:Off Append:Off ] 
A5: Else 
A6: Variable Set [ Name:%timeperoid To:evening Recurse Variables:Off Do Maths:Off Append:Off ] 
A7: End If 
A8: Return [ Value:%timeperoid Stop:On ]

and my 2nd task GTP TEST

GTP TEST (149)
A1: Perform Task [ Name:Get Time Peroid Priority:%priority Parameter 1 (%par1): Parameter 2 (%par2): Return Value Variable: Stop:Off ] 
A2: Flash [ Text:Good %timeperoid Logan Long:Off ]

This is as far as I can get I dont know how or where to edit the contributed script above. Could you perform the edit and show me please?

To unsubscribe from this group and all its topics, send an email to tasker+unsubscribe@googlegroups.com.

Scott

unread,
Jan 25, 2017, 6:00:23 PM1/25/17
to Tasker
You may want Brian to confirm this, but I believe the intent is for you to put "%timeperiod" (no quotes) in the "Return Value Variable" field in A1 (Perform Task) of GTP TEST.

His Task sets either "morning", "afternoon" or "evening" as the return value, but you need to set a local variable in your task to populate that value.  My guess is the reason he did it that was was to avoid having another global variable taking up resources.  It's a pretty good solution.

Logan Fury

unread,
Jan 25, 2017, 6:07:52 PM1/25/17
to tas...@googlegroups.com
Scott you nailed it :)

I found the Value easily once pointed at the correct task. I am very new to Tasker so ive very few if any globals beginning to become a resource issue atm, im  happy to use this solution.

Just got my first correct "Good afternoon Logan" response from the phone and im very happy.

Thank you very much for the time and help!

To unsubscribe from this group and all its topics, send an email to tasker+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages