Recursive Tasker Call

291 views
Skip to first unread message

gnomed

unread,
May 9, 2014, 6:40:16 PM5/9/14
to tas...@googlegroups.com
TL;DR -> If you don't care about my rambling/background information; skip to the task I wrote out/attached and tell me why it is not writing anything to the text file?




I was trying to solve a problem using a tasker task which would call itself recursively in a loop (traversing folders). I have since discovered I don't need to do something so complex, but I would like to know why it was failing still.

My issue is that I need to trigger a media scan of some downloaded files. The program doing the downloading doesn't scan them (and I have reported it to the dev who is "working on it") so when I plug my phone into my PC I can't see the files.

In the past I could use the tasker media scan function to scan a folder and it would nicely scan that folder and all its subfolders recursively. I swear (maybe I am crazy) that sometime in the recent past this stopped working (I KNOW android changed media scanning functionality in their framework which is why my downloading app broke in the first place) and you had to scan files individually (folders would never work).

So I was fed up today with this other downloading app not scanning its downloaded files and decided to use tasker to scan my downloads folder. Since attempting this I have discovered that media scan in tasker was fixed (maybe it was never broken) to recursively scan folders again, so all my work was for nothing. But I could not figure out why it was failing. The task is super super simple. But it would just stop randomly and not even successfully scan the files on the top level of the directory (and you would think at least those would work since they do not require a recursive call).

Here is my task typed out, and I have attached the xml backup. I also changed the else conditional to just write the filename to a text file (instead of scan the media since that would be hard for anyone to verify if the media scan worked). My test text file is always empty even excluding items in the top level directory.

Task Name: Media Scan Folder

1. List Files %para1 into $files
2. For $file in $files()
    3. Test File Type into $file_type
    4. if($file_type~dir)
        5. Call Media Scan Folder; Parameter 1 = $file //recursive call
    6. Else if ($file_type~file)
        7. Write $file to test.txt
    8. End If
9. End For

No matter what priority I set for the subtask, nothing gets scanned (written to the test output file) at all.

I was using flash alerts to try and do some debugging but I could not figure out why it wasn't working. It just stops.

Again, I have solved my problem by simply calling the media scan function on the folder itself (now that I realize that works again), but I am curious what about this super simple task is failing. I must be doing something extremely silly, this should be so simple by the sounds of the tasker guide.

Thanks for any help,
B.
tasker.xml

Jeremy Harris

unread,
May 9, 2014, 6:59:24 PM5/9/14
to tas...@googlegroups.com
The dollar signs are confusing me. What are they?

List Files, /folder/subfolder/, %var

For, %scan, %var()

Should it look something more like that, to start with?

gnomed

unread,
May 9, 2014, 7:01:49 PM5/9/14
to tas...@googlegroups.com
Sorry, I must have got a little mixed up. $ is the convention for linux variables, d'oh. Just replace '$' with '%' but I'll run back through and fix it now.

gnomed

unread,
May 9, 2014, 7:04:38 PM5/9/14
to tas...@googlegroups.com
Double shucks, I can't edit (total newb here for google groups). Here is the edited version:

1. List Files %para1 into %files
2. For %file in %files()
    3. Test File Type into %file_type
    4. if(%file_type~dir)
        5. Call Media Scan Folder; Parameter 1 = %file //recursive call
    6. Else if (%file_type~file)
        7. Write %file to test.txt
    8. End If
9. End For

On Friday, May 9, 2014 5:59:24 PM UTC-5, Jeremy Harris wrote:

Jeremy Harris

unread,
May 9, 2014, 7:13:53 PM5/9/14
to tas...@googlegroups.com
Ah, lol.

What happens if you substitute %para1 with the actual directory the files are in?

Jeremy Harris

unread,
May 9, 2014, 7:19:39 PM5/9/14
to tas...@googlegroups.com
Or what is contained in %para1?

gnomed

unread,
May 9, 2014, 8:35:43 PM5/9/14
to tas...@googlegroups.com
The interpretation of %par1 seems to work fine and find the directory I expect it to.

For my test I just have another task that calls this task and sets parameter 1 to "Download" (tasker seems to be fine with relative or absolute paths). I also tested with an absolute path to a folder inside my downloads folder (i.e. the same folder that one of the recursive calls should have executed my task on) and that also worked fine (found folder, looped through files).

I tested my loop by just flashing the file names and that worked fine. I also tested my if-conditional in a similar way and each flash message correctly identified whether something was a file or folder so I know the if condition and loop is working as I expect. The issue happens when it tries to call itself; the whole thing just stops. No more flash messages from anything; my parent task stops flashing messages and none of the child tasks flash messages so as far as I can tell it just dies...

I am not sure how hard it would be but you might be able to import that XML file I attached initially (than you'd have a direct test case to mess with). I stripped out everything except the task definition so someone could hopefully paste that into their backed up settings and then re-import. You may need to tweak some values in the xml like 'id' to make sense, but other than that it looks like it should import fine although I haven't tested. Is there a better way to share a task?

Thanks much for your responses too btw.

Matt R

unread,
May 9, 2014, 8:40:18 PM5/9/14
to tas...@googlegroups.com
Export the task description (long-press the task name and select menu -> export -> description to clipboard) and paste it in a reply here. Then we don't have to worry about typos.

Matt

gnomed

unread,
May 9, 2014, 8:46:24 PM5/9/14
to tas...@googlegroups.com
That works. Thanks for the tip. Here ya go:

Media Scan Folder (24)
A1: List Files [ Dir:%par1 Match: Include Hidden Files:Off Use Root:Off Variable:%files ] 
A2: For [ Variable:%file Items:%files() ] 
A3: Test [ Type:File Type Data:%file Store Result In:%file_type ] 
A4: If [ %file_type ~ dir ]
A5: Perform Task [ Name:Media Scan Folder Stop:Off Priority:%priority Parameter 1 (%par1):%file Parameter 2 (%par2): Return Value Variable: ] 
A6: Else If [ %file_type ~ file ]
A7: Write File [ File:Download/test.txt Text:%file Append:On Add Newline:On ] 
A8: End If 
A9: End For 

And here is the XML equivalent (I always prefer XML but that might be a personal thing):

<TaskerData sr="" dvi="1" tv="4.3u4m">
<Task sr="task24">
<cdate>1399668713439</cdate>
<edate>1399682471399</edate>
<id>24</id>
<nme>Media Scan Folder</nme>
<pri>10</pri>
<Action sr="act0" ve="5">
<code>412</code>
<Str sr="arg0" ve="3">%par1</Str>
<Str sr="arg1" ve="3"/>
<Int sr="arg2" val="0"/>
<Int sr="arg3" val="0"/>
<Str sr="arg4" ve="3">%files</Str>
</Action>
<Action sr="act1" ve="5">
<code>39</code>
<Str sr="arg0" ve="3">%file</Str>
<Str sr="arg1" ve="3">%files()</Str>
</Action>
<Action sr="act2" ve="5">
<code>115</code>
<Int sr="arg0" val="4"/>
<Str sr="arg1" ve="3">%file</Str>
<Str sr="arg2" ve="3">%file_type</Str>
</Action>
<Action sr="act3" ve="5">
<code>37</code>
<ConditionList sr="if">
<Condition sr="c0" ve="2">
<lhs>%file_type</lhs>
<op>0</op>
<rhs>dir</rhs>
</Condition>
</ConditionList>
</Action>
<Action sr="act4" ve="5">
<code>130</code>
<Str sr="arg0" ve="3">Media Scan Folder</Str>
<Int sr="arg1" val="0"/>
<Int sr="arg2">
<var>%priority</var>
</Int>
<Str sr="arg3" ve="3">%file</Str>
<Str sr="arg4" ve="3"/>
<Str sr="arg5" ve="3"/>
</Action>
<Action sr="act5" ve="5">
<code>43</code>
<ConditionList sr="if">
<Condition sr="c0" ve="2">
<lhs>%file_type</lhs>
<op>0</op>
<rhs>file</rhs>
</Condition>
</ConditionList>
</Action>
<Action sr="act6" ve="5">
<code>410</code>
<Str sr="arg0" ve="3">Download/test.txt</Str>
<Str sr="arg1" ve="3">%file</Str>
<Int sr="arg2" val="1"/>
<Int sr="arg3" val="1"/>
</Action>
<Action sr="act7" ve="5">
<code>38</code>
</Action>
<Action sr="act8" ve="5">
<code>40</code>
</Action>
</Task>
</TaskerData>

Thanks much everyone!

Rich D

unread,
May 9, 2014, 8:51:12 PM5/9/14
to Tasker Google Groups Post


> A5: Perform Task [ Name:Media Scan Folder Stop:Off Priority:%priority Parameter 1 (%par1):%file Parameter 2 (%par2): Return Value Variable: ] 

I have never tried calling the same task from within a task but you will need to change the task collision properties for this to hopefully  work. When in the task edit screen in the lower right tap the three sliders and set the task collision to 'run both together'..  it should work..

gnomed

unread,
May 9, 2014, 8:59:21 PM5/9/14
to tas...@googlegroups.com
I KNEW I was doing something silly!

That is totally it and totally obvious. *facepalm*

Changed that one thing, backed out of tasker and opened it again, ran my test case, got expected results.

In case anyone is wondering, maybe this is known, but you have to back out of tasker and open it again when testing this in order for it to use any changes to the task. It's weird, you dont have to kill tasker, the background process can stay up, you just have to back out and re-open the main activity. Something to do with the fact that I am editing a different task than the one I am running I think. (because this is a recursive function I have to test it from another task) If I edit a task and then run it right there tasker will run the new task, but if I edit a task, then use another task to run my edited task, it will run a cached version of the task it seems. Oh well, that's a separate issue I am not gonna push, but figured I would mention it here in case anybody is playing with the test case.

Thanks everyone!
Reply all
Reply to author
Forward
0 new messages