Event when new file is in directory

2,944 views
Skip to first unread message

francwalter

unread,
Mar 6, 2012, 3:54:23 PM3/6/12
to tas...@googlegroups.com
Hello

I am looking for a way to change the filenames of pictures which are taken from Camera360 App on my SGS2 with 2.3.5
I have bought Tasker and I have the actual Version.
Now I thought if I make an event when the directory properties of sdcard/DCIM/camera changed, which is the case when I receive there a new picture, because the date of the dir is changing.

But this is not noticed by Tasker. Only if e.g. the write-access is changed, this event is triggered.

How can Tasker detect now, that there is a new file in the photo directory?
Is this not possible to check at all?

How can I trigger an event after a new foto is in my camera-folder?

Kindly regards, frank walter

Pent

unread,
Mar 7, 2012, 4:30:55 AM3/7/12
to Tasker
> Now I thought if I make an event when the directory properties of *
> sdcard/DCIM/camera* changed, which is the case when I receive there a new
> picture, because the date of the dir is changing.

There is only one camera subdirectory in DCIM isn't there ?

I have it on my short(ish) list already to look at why File Changed
isn't working
with a directory.

As a workaround, you can check e.g. every 15 minutes if there are any
files
there younger than 15 minutes and rename them then (there a forum
topic
on that somewhere, have a search).

Pent

franc walter

unread,
Mar 7, 2012, 4:41:36 AM3/7/12
to tas...@googlegroups.com

There are four under DCIM:

/sdcard/DCIM/.thumbnails
/sdcard/DCIM/100ANDRO
/sdcard/DCIM/Camera
/sdcard/DCIM/Timesheet

And in the directory Camera there is another sub dir "cache"

Is it a bug?

Pent

unread,
Mar 7, 2012, 4:48:34 AM3/7/12
to Tasker
So did you tried DCIM/Camera ?

(without a *)

Pent

franc walter

unread,
Mar 7, 2012, 5:28:02 AM3/7/12
to tas...@googlegroups.com

I choose it with the file selector and long press.
But I tried:
/sdcard/DCIM/Camera
/sdcard/DCIM/Camera/
/sdcard/DCIM/Camera/*

No success

Edward Ned Harvey

unread,
Mar 7, 2012, 8:23:06 AM3/7/12
to Tasker
> From: tas...@googlegroups.com [mailto:tas...@googlegroups.com] On
> Behalf Of Pent

>
> As a workaround, you can check e.g. every 15 minutes if there are any
> files

Or check when the camera app is closed.

Pent

unread,
Mar 7, 2012, 9:31:17 AM3/7/12
to Tasker
> Or check when the camera app is closed.

Yes, good one.

franc walter

unread,
Mar 7, 2012, 9:36:08 AM3/7/12
to tas...@googlegroups.com
Sorry, I don't find this event.
When I add a profile I have "App" as context, but there is no event, "when App closes" or similar.

Could you indicate?

Pent

unread,
Mar 7, 2012, 10:22:10 AM3/7/12
to Tasker
> When I add a profile I have "App" as context, but there is no event, "when
> App closes" or similar.

Once you've created an app context, long-click on the task and select
Move To Exit.

Pent

franc walter

unread,
Mar 7, 2012, 4:40:49 PM3/7/12
to tas...@googlegroups.com
Ah, thank you, now it triggers.
I switched the language to english so I can better understand (in german it is: "Ausgangstask hinzufügen").

But now I have a remaining problem: I have a script with several commands and comments (starting with "#") but this doesn't work.
E.g.:
cd /my/new/path/
for i in *.jpg; do ...
another command
etc.


How can I start several commands, do I have to make for each command line a new action (Plugin / Execute)?

franc walter

unread,
Mar 7, 2012, 6:31:16 PM3/7/12
to tas...@googlegroups.com
Yahoo, I discovered and installed SL4A (and some Interpreters) for Tasker and all is fine :)
Now I can write and run my own scripts (bash, phyton, php etc.) in:

/sdcard/sl4a/scripts/

with:

Misc / Run Script

More and more I think, that Tasker is quite mighty :)

franc walter

unread,
Mar 8, 2012, 4:35:15 AM3/8/12
to tas...@googlegroups.com
Works like a charm now!
Thank you againly for your support, Pent

Nice day,

franc

Pent

unread,
Mar 8, 2012, 5:43:41 AM3/8/12
to Tasker
> Now I can write and run my own scripts (bash, phyton, php etc.) in:

Puh, you don't need all that :-)

List Files DCIM/Camera -> %files
For %file, %files
Test, File Age, %file -> %age
If %TIMES - %age < 3600
Alert / Flash New File: %file
Move File %file...
EndIf
EndFor

Pent

franc walter

unread,
Mar 8, 2012, 6:59:45 AM3/8/12
to tas...@googlegroups.com
Is this ONE command?
This is a script, I didn't get more than one command to run, do you?
How this then?
With Plugin / Execute?
Or with Misc / Run Shell?

Edward Ned Harvey

unread,
Mar 8, 2012, 9:56:53 AM3/8/12
to tas...@googlegroups.com
> Behalf Of franc walter

>
> Is this ONE command?
> This is a script, I didn't get more than one command to run, do you?
> How this then?
> With Plugin / Execute?
> Or with Misc / Run Shell?

New profile "Camera Running"
Context: Application / Camera

New task: "Camera Mode Start"
Variable / Set / %startcamtime = %TIMES - 30 (do maths)
(Note, %TIME is a decimal number. Right now it's 9:46 am, so %TIME = 9.46. Not good for math.
%TIMES is time in seconds from the epoch. Good for math.)
(I subtract 30 sec just in case tasker takes a few seconds to
trigger the context when the camera opens.)
Save.

Long-click the "Camera Mode Start" task in your profile. Add Exit Task.

New task: "Camera Mode End"
File / List Files / (choose dir, choose var name %files)
Task / For / %file in %files
Misc / Test / File Modified / %file, %filetime
Task / If / %filetime > %startcamtime
File / Move / (whatever you like)
(upload to dropbox, whatever you like...)
Task / End If
Task / End For

Pent

unread,
Mar 8, 2012, 10:16:20 AM3/8/12
to Tasker
> Is this ONE command?

No, it's 8 Tasker actions.

Pent

franc walter

unread,
Mar 8, 2012, 10:24:36 AM3/8/12
to tas...@googlegroups.com

Thank you
I see, with tasker there are many ways to Rome
:)
With the script it is working as well since yesterday
Is script less good?

Matt R

unread,
Mar 19, 2013, 2:29:20 PM3/19/13
to tas...@googlegroups.com
It would be better (more readable) to post the exported descriptions instead of the exported xml.

Matt

Mark Mathis

unread,
Mar 19, 2013, 2:40:26 PM3/19/13
to tas...@googlegroups.com
On Tuesday, March 19, 2013 2:29:20 PM UTC-4, Matt R wrote:
It would be better (more readable) to post the exported descriptions instead of the exported xml.

Matt

Ahh..yes, of course it would, sorry.  So used to attaching xml for various things :).

Here are the exported Descriptions, one based of Pent's and one based off Ned's

Test 2 (24)
A1: List Files [ Dir:Download Match: Include Hidden Files:Off Variable:%files ] 
A2: For [ Variable:%file Items:%files ] 
A3: Test [ Type:File Modified Data:%file Store Result In:%age ] 
A4: If [ %TIMES - %age < 3600 ]
A5: Flash [ Text:File mod Long:Off ] 
A6: End If 
A7: End For 

 or 

Test (17)
A1: Variable Set [ Name:%runtime To:%TIME Do Maths:Off Append:Off ] 
A2: List Files [ Dir:Download Match: Include Hidden Files:Off Variable:%files ] 
A3: For [ Variable:%file Items:%files ] 
A4: Test [ Type:File Modified Data:%file Store Result In:%filetime ] 
A5: If [ %filetime > %runtime ]
A6: Flash [ Text:Mod Long:Off ] 
A7: End If 
A8: End For 
 

Matt R

unread,
Mar 19, 2013, 4:07:02 PM3/19/13
to tas...@googlegroups.com
In the for loop, you need to change %files to %files() (so that it uses the entire %files array).

Matt

Mark Mathis

unread,
Mar 20, 2013, 12:09:47 AM3/20/13
to tas...@googlegroups.com
On Tuesday, March 19, 2013 4:07:02 PM UTC-4, Matt R wrote:
In the for loop, you need to change %files to %files() (so that it uses the entire %files array).

Matt

Ahh, yes, that does make sense.  Thank you.  I have tweaked a bit since I ran into some issues with Tasker's Move command (cross link error possibly?), so I changed to a copy step and a remove step for now...  The Flash is just there for me testing the task and will be removed.   All this just b/c we can't set default Download dir to the external SD Card :(.

Now I just have to decide how I want to trigger this ;).  Probably just on time for now, adjusting the math accordingly.  Or maybe something with the downloads app even...

 Sync - Download (24)
A1: List Files [ Dir:Download Match: Include Hidden Files:Off Variable:%files ] 
A2: For [ Variable:%file Items:%files() ] 
A3: Test [ Type:File Modified Data:%file Store Result In:%age ] 
A4: If [ %TIMES - %age < 3600 ]
A5: Flash [ Text:Modded %file Long:Off ] 
A6: Copy File [ From:%file To:/extSdCard/Download Use Root:On ] 
A7: Delete File [ File:%file Shred Level:0 Use Root:On ] 
A8: End If 
A9: End For 

Mark Mathis

unread,
Mar 24, 2013, 1:21:33 AM3/24/13
to tas...@googlegroups.com
Well all works great, but essentially it's just doing the same as Foldersync would, that is just checking based on a timed schedule profile.

Looking for a way to automate this based on new file existing in the sdcard/Downloads directory.  I've looked at File Change, Dir Change, Notification (ie, "download complete", etc but not having much success.  Was hoping to tie it into Downloads App/Download Manager, but no success yet.  I'll keep fiddling with it :).

RudeboyX

unread,
Jun 4, 2013, 5:27:22 AM6/4/13
to tas...@googlegroups.com
This is somthing I'm very interested in. I've never been able to get "File changed" to work for folders with any Tasker version or ROM on any of my devices and have so many possible uses for it. Have you had any luck in getting this working yet Pent?
 
RBX

On Wednesday, 7 March 2012 09:30:55 UTC, Pent wrote:
I have it on my short(ish) list already to look at why File Changed
isn't working
with a directory.

Pent

Pent

unread,
Jun 4, 2013, 7:21:45 AM6/4/13
to Tasker
> This is somthing I'm very interested in. I've never been able to get "File
> changed" to work for folders with any Tasker version or ROM on any of my
> devices and have so many possible uses for it. Have you had any luck in
> getting this working yet Pent?

Yes, I just tested it 30 seconds ago, responded fine to file deletion
and creation
in a dir on SD (N7, stock 4.2.2)

Pent

RudeboyX

unread,
Jun 4, 2013, 10:58:52 AM6/4/13
to tas...@googlegroups.com
Thanks Pent
 
   I managed to get it to work with "File Modified" and removing the file name from the selection (leave the trailing "/" in place)
 
However It didnt work for changes in sub directories of that folder. I guess I can setup multiple profiles for this though
 
Thanks for the assistance
RBX
 
 
 
what goes in the "File" field? as tasker only lets you pick a file via its inbuilt browser. no matter

Pent

unread,
Jun 4, 2013, 12:24:15 PM6/4/13
to Tasker
>    I managed to get it to work with "File Modified" and removing the file
> name from the selection (leave the trailing "/" in place)

Yes, when a file is e.g. removed from the directory it's the directory
that is
modified, not the file.

> However It didnt work for changes in sub directories of that folder.

No, that's not signalled by Android. Technically, removing a file from
a subfolder does not change the parent folder at all, so it's correct.

Pent

Mark Mathis

unread,
Jun 14, 2013, 10:22:24 PM6/14/13
to tas...@googlegroups.com
This is now working for me as well using the trailing / in place.  Oh I am going to have fun with this  :)  Thanks

Brad Buran

unread,
Nov 2, 2013, 9:39:45 AM11/2/13
to tas...@googlegroups.com
I realize this thread is a little old, but I have a similar problem.  I'd like to be able to detect when a file is added to the bluetooth folder (e.g. transmitted from another bluetooth device).  Is it possible to store the file name in a variable that can be accessed by the task?

Rich D

unread,
Nov 4, 2013, 6:15:58 AM11/4/13
to tas...@googlegroups.com

> I realize this thread is a little old, but I have a similar problem.  I'd like to be able to detect when a file is added to the bluetooth folder (e.g. transmitted from another bluetooth device).

Are you saying you have tried the 'file modified' context and it does not work on this folder?

Does it work on other folders?

 Is it possible to store the file name in a variable that can be accessed by the task?

You mean the file name of the transferred file? I am not sure if the modified status of the file changes with a transfer like that but there is a misc / test / file modified action in tasker and there are many ways to sort file names  from a shell "find" command (this may require root)

Reply all
Reply to author
Forward
Message has been deleted
0 new messages