Thank you very much Rich D! That was perfect :)
If anyone is interested - this is my finished setup. It allows me to say - ok google - "add john smith to my contacts" (or any name...) into my watch. I have a dialler on my watch, so I would dial John so he gets my number, then initiate this task.
Any suggestions for code improvements would also be appreciated :)
Profile: AV New Contact (74)
Event: AutoVoice Recognized [ Configuration:Command: "add (?<newcontactname>.+) to my contacts (regex)" ]
Enter: AV Add To Contacts (72)
A1: Perform Task [ Name:ScreenIf Priority:%priority Parameter 1 (%par1): Parameter 2 (%par2): Return Value Variable: Stop:Off ]
//ScreenIf turns my phone on and records that it was off to start with. I want to trigger this from my watch while my phone screen is off. Repitouch needs it to be on to work.
A2: Variable Set [ Name:%ConvertThis To:%newcontactname Do Maths:Off Append:Off ]
A3: Perform Task [ Name:First Word To Caps Priority:%priority Parameter 1 (%par1): Parameter 2 (%par2): Return Value Variable: Stop:Off ]
//This Task will be pasted afterwards. In short, it processes %ConvertThis into an upper case word for each word.
A4: Wait [ MS:0 Seconds:4 Minutes:0 Hours:0 Days:0 ] A5: Launch App [ App:Phone Data: Exclude From Recent Apps:Off ] A6: Wait [ MS:0 Seconds:2 Minutes:0 Hours:0 Days:0 ] A7: RepetiTouch Pro [ Configuration:Action: Start Replay (using file "/storage/emulated/0/Repitouch/AddContactA") (replaying once) with hidden panel, close after action (silent) Package:com.cygery.repetitouch.pro Name:RepetiTouch Pro Timeout (Seconds):0 ] //This series of emulated touches opens the most recent number dialled in my phone, creates a new number for them and selects the text input box.
A8: Wait [ MS:0 Seconds:8 Minutes:0 Hours:0 Days:0 ]
A9: Type [ Text:%ConvertThis Repeat Times:1 ]
// The name is typed in...
A10: Wait [ MS:0 Seconds:8 Minutes:0 Hours:0 Days:0 ] A11: RepetiTouch Pro [ Configuration:Action: Start Replay (using file "/storage/emulated/0/Repitouch/AddContactB") (replaying once) with hidden panel, close after action (silent) Package:com.cygery.repetitouch.pro Name:RepetiTouch Pro Timeout (Seconds):0 ] //A simple click on "done".
A12: Wait [ MS:0 Seconds:8 Minutes:0 Hours:0 Days:0 ]
A13: Perform Task [ Name:ScreenIfEnd Priority:%priority Parameter 1 (%par1): Parameter 2 (%par2): Return Value Variable: Stop:Off ]
//If my screen was off top begin with, please turn it off again :)
A14: Notify [ Title:Added To Contacts Text:%ConvertThis added to contacts Icon:cust_star Number:0 Permanent:Off Priority:3 ]
//Notify who was added to contacts, so I know it got the right name.
Word conversion task:
First Word To Caps (75)
A1: Variable Set [ Name:%convertthis To:%ConvertThis Do Maths:Off Append:Off ]
//Local variable ensures it is cleared each time I use the task.
A2: Variable Split [ Name:%convertthis Splitter: Delete Base:Off ]
A3: For [ Variable:%item Items:%convertthis() ]
A4: Variable Convert [ Name:%item Function:To Upper Case First Store Result In: ]
//The most important bit! Thanks Rich D!
A5: If [ %converted Set ]
A6: Variable Set [ Name:%converted To:%converted%item Do Maths:Off Append:Off ]
//Note the space after %item allows other %item 's to be added on. This leaves a space after the final run sequence though...
A7: End If
// If there is text in %converted, then add item there!
A8: If [ %converted !Set ]
A9: Variable Set [ Name:%converted To:%item Do Maths:Off Append:Off ]
A10: End If
// If there is no text, then we need to set %converted for the first time.. or it will type %converted. Placing this after line 5's if statement ensures the two do not overlap. I'm not up to speed on use of else in tasker yet.
A11: End For
A12: Variable Split [ Name:%converted Splitter: Delete Base:Off ]
//Remember that trailing space? (See comment in line A6) Split the result by spaces...
A13: Variable Set [ Name:%ConvertThis To:%converted() Do Maths:Off Append:Off ]
//The array is placed in a variable - but now %ConvertThis will be "John,Smith". The final space is not pushed as a comma. Nice :D
A14: Variable Search Replace [ Variable:%ConvertThis Search:, Ignore Case:Off Multi-Line:Off One Match Only:Off Store Matches In: Replace Matches:On Replace With: ]
//Change those commas to a " " and we're all finished!