I created a menu scene and I've created tasks that populate it with a subset of the profiles enabled at boot time. That much is working ok now. The menu element is populated from a local array variable.
I've attached the XML for the tasks and the scene. I've also included the plain text below.
Scene: Tasker User Profiles
P:1026x1608 L:-1x-1
Orientation: System
Background Colour: #FF0D0D0D
Action Bar Style: System
Title: Tasker User Profile List
Subtitle:
Icon: null
Tab Labels:
Element: ProfileMenu/Menu
Geometry:
P:0,50 969x1458 L:-1,-1 -1x-1
Content:
Source: Variable Array
Variable: %profiles
Selection Mode: None
Item Layout: Builtin Item Layout
Horizontal Space: 0
Vertical Space: 0
Events:
ItemClick: 97
Profile Menu - Show (76)
A1: Notify [ Title:Building Profile Menu Text: Icon:cust_icon_donut Number:0 Permanent:On Priority:3 ]
A2: Array Clear [ Name:%profiles ]
A3: Array Clear [ Name:%profilesreal ]
A4: Variable Set [ Name:%profs To:%DeviceProfiles Do Maths:Off Append:Off ]
A5: Variable Split [ Name:%profs Splitter:, Delete Base:Off ]
A6: Variable Set [ Name:%cnt To:0 Do Maths:Off Append:Off ]
A7: For [ Variable:%prof Items:%profs() ]
A8: If [ %prof ~ *-* user* ]
A9: Variable Add [ Name:%cnt Value:1 Wrap Around:0 ]
A10: Array Push [ Name:%profilesreal Position:%cnt Value:%prof Fill Spaces:Off ]
A11: Perform Task [ Name:Get Profile With State Name Stop:Off Priority:9
Parameter 1 (%par1):%prof Parameter 2 (%par2): Return Value
Variable:%profwstate ]
A12: Array Push [ Name:%profiles Position:%cnt Value:%profwstate Fill Spaces:Off ]
A13: End If
A14: End For
A15: Array Process [ Variable:%profiles Type:Sort Alpha ]
A16: Array Process [ Variable:%profilesreal Type:Sort Alpha ]
A17: Show Scene [ Name:Tasker User Profiles Display As:Activity, Full
Window Horizontal Position:100 Vertical Position:100 Animation:None Show
Exit Button:On Continue Task Immediately:On ]
A18: Notify Cancel [ Title:Building Profile Menu Warn Not Exist:Off ]
Get Profile With State Name (99)
A1: Variable Set [ Name:%prof To:%par1 Do Maths:Off Append:Off ]
A2: Perform Task [ Name:Get Profile State Name Stop:Off Priority:10
Parameter 1 (%par1):%prof Parameter 2 (%par2): Return Value
Variable:%statename ]
A3: Variable Split [ Name:%prof Splitter:- Delete Base:Off ]
A4: Return [ Value:%prof1 [%statename] Stop:On ]
Get Profile State Name (109)
A1: Return [ Value:Triggered Stop:On ] If [ %PACTIVE ~ *,%par1,* ]
A2: Return [ Value:Ready Stop:On ] If [ %PENABLED ~ *,%par1,* ]
A3: Return [ Value:Disabled Stop:On ]
There's an action in the scene category called element text color. Works great I used to use it to tell when something was enabled/disabled, before Pent added on/off switches
Jay M
Ar you used a menu element I thought you ment you made some kind of a menu scene because you wrote menu scene, I forgot theres a actual menu element my bad.
Jay M
--
You received this message because you are subscribed to the Google Groups "Tasker" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tasker+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/tasker.
For more options, visit https://groups.google.com/groups/opt_out.
> Now I would like to visually indicate (beyond just the current state text in square brackets after each profile name) which one of 3 "states" a profile is in (disabled, enabled but inactive, active) by changing the color of individual items in the menu and/or add one of 3 icons to each individual menu item.
I am still on the old UI so I really can't help with this, I thought something like that was on the wish list for scenes but i have no idea if pent was able to implement it.
> My current method for chopping off the - suffix (containing things like Phone and User) from the profile names and adding the state name (like [Ready]) is currently a bit slow
In my experience using a for loop for this kind of operation can be slow and the perform tasks probably add to the problem.
If you read the user guide for variables / arrays you will find a search action for a array. Between that and variable search and replace I have always been able to achieve what you are trying to do without the use of a for loop. Even if you have to spit and rejoin the array several times these search features are much faster than a for loop. You might consider doing it all within one task even if it means writing the same code again for other tasks. Of course always use local variables as well even if it means changing form global to local for the search then back to global.
> I don't see how I could get rid of the for loop.
OK here is a stab at it.....
You will need to learn a little regex..
You somehow must have a list of all your profiles, call this the '%master list'
And we have %PENABLED and %PACTIVE
Assuming all three are in a normal, comma separated format you should be able to get 3 different variables of the profile names in the 3 states you want by. using variable search and replace with regex.
This is just one example of how too remove the profiles enabled from the master list
Search and replace (74)
//Set the lists//
A1: Variable Set [ Name:%master To:,a,b,c,d,e,f,g, Do Maths:Off Append:Off ]
A2: Variable Set [ Name:%penabled To:,b,a,d, Do Maths:Off Append:Off ]
// remove first and last commas //
A3: Variable Search Replace [ Variable:%penabled Search:(^,|,$) Ignore Case:On Multi-Line:On One Match Only:Off Store Matches In: Replace Matches:On Replace With: ]
// replace commas with pipes ( this sets up the proper regex search criteria) //
A4: Variable Search Replace [ Variable:%penabled Search:, Ignore Case:On Multi-Line:On One Match Only:Off Store Matches In: Replace Matches:On Replace With:,|, ]
A5: Flash [ Text:%penabled Long:On ]
// find all profiles in %penabled and delete them from %master ( just leave the "replace with" field empty //
A6: Variable Search Replace [ Variable:%master Search:( %penabled) Ignore Case:On Multi-Line:On One Match Only:Off Store Matches In: Replace Matches:On Replace With: ]
A7: Flash [ Text:%master Long:Off ]
Regex conditions are easily found with google search.
You should be able to complete what you're trying to do with similar operations.
It might seem like quite a few more steps but it will be much faster.
I could not find a way to negate that pattern (there is [^xyz] to find characters not in a set, but I couldn't find a similar operator to apply to an entire regular expression). I could probably have used the variable search feature that writes matches to an array, but at that point what is the advantage of variable search vs. the array for loop I was already using?
I believe the advantage would be it would still be faster especially if you have alot of profile names to iterate through.
You seem to have achieved a speed suitable for you so i would imagine you will stay with what you have. However I did claim earlier that it would be possible to do this without using a for loop so i could not rest until that happened... :)
Making this actually helped my understanding of regex alot better, so it was very helpful to me if no one else..
Just to keep the record straight here is a task that will do what you want ( I think) you should end up with the 2 sorted lists
%Adisabled = profiles with 'user' that are diabled
%Aenabled_inactive = profiles enabled but inactive with 'user'
I figure getting the profiles active with 'user' would be easy enough ...
I attached the XML as well...
Regex Search Profile Names (74)
<set variables>
A1: Anchor
A2: Variable Set [ Name:%master To:,Profile 1 - User truck , Profile 2 - Car phone , Profile 3 , Profile 4 - House - User, Profile 5 , Profile 6 - Gym Car , Profile 7 - User phone, Profile 8 - Phone house , Profile 9 - Steve Phone User, Do Maths:Off Append:Off ]
A3: Variable Set [ Name:%penabled To:, Profile 2 - Car phone , Profile 3 , Profile 4 - House - User, Profile 5 , Profile 6 - Gym Car , Profile, Profile 8 - Phone house , Profile 9 - Steve Phone User, Do Maths:Off Append:Off ]
A4: Variable Set [ Name:%pactive To:,Profile 1 - User truck , Profile 2 - Car phone , Profile 5 , Do Maths:Off Append:Off ]
<set not enabled>
A5: Anchor
A6: Variable Set [ Name:%enabled_sort To:%penabled Do Maths:Off Append:Off ]
A7: Variable Set [ Name:%master_sort To:%master Do Maths:Off Append:Off ]
A8: Variable Search Replace [ Variable:%master_sort Search:, Ignore Case:On Multi-Line:On One Match Only:Off Store Matches In: Replace Matches:On Replace With:,, ]
A9: Variable Search Replace [ Variable:%enabled_sort Search:(^,|,$) Ignore Case:On Multi-Line:On One Match Only:Off Store Matches In: Replace Matches:On Replace With: ]
A10: Variable Search Replace [ Variable:%enabled_sort Search:, Ignore Case:On Multi-Line:On One Match Only:Off Store Matches In: Replace Matches:On Replace With:,|, ]
A11: Variable Set [ Name:%enabled_sort To:,%enabled_sort, Do Maths:Off Append:Off ]
A12: Variable Search Replace [ Variable:%master_sort Search:%enabled_sort Ignore Case:On Multi-Line:On One Match Only:Off Store Matches In:%match Replace Matches:On Replace With: ]
A13: Variable Search Replace [ Variable:%master_sort Search:,, Ignore Case:On Multi-Line:On One Match Only:Off Store Matches In: Replace Matches:On Replace With:, ]
A14: Variable Set [ Name:%adisabled To:%master_sort Do Maths:Off Append:Off ]
A15: Flash [ Text:%adisabled Long:Off ]
A16: Stop X [ With Error:Off Task: ]
<set enabled and inactive>
A17: Anchor
A18: Variable Set [ Name:%enabled_sort To:%penabled Do Maths:Off Append:Off ]
A19: Variable Set [ Name:%active_sort To:%pactive Do Maths:Off Append:Off ]
A20: Variable Search Replace [ Variable:%enabled_sort Search:, Ignore Case:On Multi-Line:On One Match Only:Off Store Matches In: Replace Matches:On Replace With:,, ]
A21: Variable Search Replace [ Variable:%active_sort Search:(^,|,$) Ignore Case:On Multi-Line:On One Match Only:Off Store Matches In: Replace Matches:On Replace With: ]
A22: Variable Search Replace [ Variable:%active_sort Search:, Ignore Case:On Multi-Line:On One Match Only:Off Store Matches In: Replace Matches:On Replace With:,|, ]
A23: Variable Set [ Name:%active_sort To:,%active_sort, Do Maths:Off Append:Off ]
A24: Variable Search Replace [ Variable:%enabled_sort Search:%active_sort Ignore Case:On Multi-Line:On One Match Only:Off Store Matches In:%match Replace Matches:On Replace With: ]
A25: Variable Search Replace [ Variable:%enabled_sort Search:,, Ignore Case:On Multi-Line:On One Match Only:Off Store Matches In: Replace Matches:On Replace With:, ]
A26: Variable Set [ Name:%aenabled_inactive To:%enabled_sort Do Maths:Off Append:Off ]
A27: Flash [ Text:%aenabled_inactive Long:Off ]
A28: Stop X [ With Error:Off Task: ]
<trim list 'User'>
A29: Anchor
A30: Variable Search Replace [ Variable:%adisabled Search:([a-zA-Z1-9 ])?[^,]+(User)[^,]*([a-zA-Z1-9 ])? Ignore Case:On Multi-Line:On One Match Only:Off Store Matches In:%Abdisabled Replace Matches:On Replace With: ]
A31: Variable Search Replace [ Variable:%aenabled_inactive Search:([a-zA-Z1-9 ])?[^,]+(User)[^,]*([a-zA-Z1-9 ])? Ignore Case:On Multi-Line:On One Match Only:Off Store Matches In:%Abenabled_inactive Replace Matches:On Replace With: ]
A32: Variable Set [ Name:%Adisabled To:%Abdisabled(:) Do Maths:Off Append:Off ]
A33: Variable Set [ Name:%Aenabled_inactive To:%Abenabled_inactive(:) Do Maths:Off Append:Off ]
A34: Flash [ Text:%Adisabled.
%Aenabled_inactive Long:On ]