Deleting or editing specific lines in text file

440 views
Skip to first unread message

Profajl Nejm

unread,
Feb 5, 2015, 11:29:56 PM2/5/15
to tas...@googlegroups.com
Hi, I'm working on a shopping list and so far I have been able to create a button/function that can add items to the list by appending a line to my shopping.txt.

I have a scene that shows every line from the txt as a separate text element. I want to be able to tap each element and have Tasker delete the corresponding line in the txt file.
I would also be ok with being able to change any specific line to read "EOF" (I use EOF to check if the line is "occupied" because I have a a 13 line limit in my shopping list scene - e.g if the line's variable contains EOF it means the shopping list has less than 13 items).

So far the only way i've come up with is to record all the shopping items with each element tap, and then delete the shopping txt and re-create it with only the new varibles (i.e the ones who weren't deleted via tapping on them), but this feels slightly sub-optimal functionality-wise.

thanks for any help provided :)

Patrik

Robert Ryan

unread,
Feb 6, 2015, 2:00:43 AM2/6/15
to tas...@googlegroups.com
A possibly more efficient way to do this would be to load an array with the lines from the txt file before showing the scene.

Array Push can then be used to add new items. Removing an item could be done by clearing that particular array element and using Array Process Squash.

Only when you are ready to dismiss the scene would you erase the old text file and write a new one using the array.

Rich D

unread,
Feb 6, 2015, 6:01:47 AM2/6/15
to Tasker Google Groups Post


> Hi, I'm working on a shopping list

Nice project. I would be the last one to suggest a play store app over doing yourself with tasker, However I feel I would be very negligent if I did not recommend "Mighty Grocery "   it is one aid the very few paid apps I have.

That being said...

> I have a scene that shows every line from the txt as a separate text element.

I absolutely use a menu element to display the list and use a comma separated variable  to populate the menu. This would eliminate the need for a text file.  For making changes to the variable (list) you would split it into a array and process the data with array push, array pop and array search.   


I want to be able to tap each element and have Tasker delete the corresponding line

Very easy using the %tap_index variabe in the menu element

That is just the way I would go....  :)

Scott

unread,
Feb 6, 2015, 9:35:17 AM2/6/15
to tas...@googlegroups.com
That's very similar to how I do it. 

I load the array exactly as described.

I use Array Push to add elements.

I use Array Pop to delete the selected element.

I have a Save button that writes it to a file (you don't need to actively delete the file, you can just over right it by not appending).

I like the separate Save button because I can undo all my changes by destroying the scene without saving.  Having the text file is nice because you can back it up and you don't need a separate, global array for each list.  With Minimalistic text I can read any of my list files and display whatever list I want on whatever widget I want.  So when I go to a specific place I can have the most appropriate list displayed on my lock screen.  

Profajl Nejm

unread,
Feb 6, 2015, 9:33:26 PM2/6/15
to tas...@googlegroups.com
Oh, i figured i might have to learn the arrays.... haven't tinkered with arrays for several years so i'm a little annoyed with that, but perhaps the learning curve isn't too bad. I definitely want to use a text file tho, i like text files and "portable settings" as it were.

So i should start with having each item of the list on the same line in the text file, like "candy|fruit|chloroform|birthday present" ?

Rich D

unread,
Feb 6, 2015, 10:05:56 PM2/6/15
to Tasker Google Groups Post


> Oh, i figured i might have to learn the arrays.... haven't tinkered with arrays for several years so i'm a little annoyed with that, but perhaps the learning curve isn't too bad.

Should not be...

I definitely want to use a text file tho, i like text files and "portable settings" as it were.

Not sure what you mean by 'portable settings'? 

>
> So i should start with having each item of the list on the same line in the text file, like "candy|fruit|chloroform|birthday present" ?

Correct, but use a comma separator.  That is what the menu element will accept to load the menu items.

Rich D

unread,
Feb 6, 2015, 10:18:59 PM2/6/15
to Tasker Google Groups Post


> > So i should start with having each item of the list on the same line in the text file, like "candy|fruit|chloroform|birthday present" ?
>
> Correct, but use a comma separator.  That is what the menu element will accept to load the menu items.

On second thought if you are using a text file you will most likely want to populate the menu directly with the "Array" so you can use any delimiter you like.  Just read the file into a "local" variable and do a variable split. This will give you a "local" array that will load the menu.

Profajl Nejm

unread,
Feb 6, 2015, 11:35:52 PM2/6/15
to tas...@googlegroups.com
Ok thanks, i think i have it almost to a T now. I'll report back if i run into any problems :)

with portable settings i meant stuff like ini files and cfg files. Old school app data :)
Reply all
Reply to author
Forward
0 new messages