File event triggered unnecessarily

45 views
Skip to first unread message

SDS

unread,
Jan 6, 2026, 2:12:43 AM (4 days ago) Jan 6
to Tasker
In event->file->file modified(created), there is no option to choose the file type, which makes it to trigger unnecessarily and be filtered inside the task. Is there any other way to trigger only when particular type of file is modified(created or moved)? 

Marta Hintz

unread,
Jan 7, 2026, 12:55:35 AM (3 days ago) Jan 7
to Tasker
You have an Event like File Modified / File Created that fires for any file in a folder. You want the task to continue only if the file ends with .txt, and otherwise exit immediately. 

Where the file path comes from For file events (File Modified, File Created, File Moved, etc.), Tasker puts the full file path into the built‑in variable %evtprm1. 
Example:
If /storage/emulated/0/Download/test.txt is modified, %evtprm1 will contain that whole path. 
Simple version using Variable Search/Replace This is usually the easiest to read and edit later.
ProfileContext:
Event → File → File Modified (or Created/Moved)
File: point to the folder or file you’re watching.
Task actionsA1 – Variable Search ReplaceAdd action: Variables → Variable Search Replace.Variable: %evtprm1Search: .txt Ignore Case: OffMulti-Line: OffOne Match Only: On (doesn’t really matter here)Store Matches In: %match  (or any local variable name)Replace Matches: Off
Effect:If the file path contains .txt, %match will be set.If not, %match will be empty. 
A2 – IfAdd action: Task → If.Condition: %match Is Set
This creates an If block; everything between If and End If only runs for .txt files.
A3 – [Your real actions here]        Put whatever you actually want to do with .txt files here.
A4 – End IfAdd action: Task → End If.
Result:When the event fires for a .txt file → %match is set → your actions run.For other file types → %match is not set → the task basically does nothing.
```

This runs efficiently since filtering happens first.

Alternative: Directory Monitor
Use a looped task with List Files on the folder, comparing timestamps or counts against globals like `%LastTxtCount`. Trigger via Time context (every 5-10s). Less battery-friendly but fully filterable by extension in JavaScriptlet:
```
var files = files();  // From List Files
var txtCount = 0;
for (var i = 1; i <= files.length(); i++) {
  if (files(i).match(/\.txt$/)) txtCount++;
}
if (txtCount > %par1) { setGlobal("TxtChanged", 1); }
```
Pass prior count via Perform Task. Cleaner for high-activity folders. 

Hope this helps a little

Marta Hintz

unread,
Jan 7, 2026, 1:01:08 AM (3 days ago) Jan 7
to Tasker
maybe this would be better - just select the one that works or works best for you
Alternative using Variable Split (if you like)If you want to literally pull out the extension:
A1 – Variable SplitAction: Variables → Variable Split.Name: %evtprm1Splitter: .Delete Base: On (or Off, your choice).
After this, Tasker creates an array:%evtprm11, %evtprm12, …, %evtprm1N
where the last one (%evtprm1N) is the extension (e.g. txt). 
A2 – IfCondition: %evtprm1(%evtprm1(#)) ~ txt%evtprm1(#) = number of pieces after the split.%evtprm1(%evtprm1(#)) = last piece = extension.
Then put your actions inside this If / End If block as before.

This is a bit more “array‑ish”, which is why the Search/Replace method above is usually simpler to understand. 

SDS

unread,
Jan 7, 2026, 2:41:07 AM (3 days ago) Jan 7
to Tasker
I am already using in the task if  %evtprm1 ~ *.mkv/.*mp4/.*avi . But this is at the task level after profile is triggered. My question is whether at the profile level only can we do such type of filtering and prevent the task to be fired if the filepath does not contain the file with the extension mentioned. I think currently there is no such feature in the tasker. Thanks for your reply anyway!

John Durso

unread,
Jan 8, 2026, 5:08:17 AM (2 days ago) Jan 8
to Tasker
I'm in the middle of setting up a similar trigger myself. I haven't gotten it triggering at all (I think it's a permissions issue) but could you not do /filepath/*.mp3 or whatever the extension that you want is?

By the way, what device are you on and what permissions did you need to give Tasker? I've given all, but haven't used the Tasker Permissions app yet.

SDS

unread,
Jan 8, 2026, 6:12:45 AM (2 days ago) Jan 8
to Tasker
I have been already using if  %evtprm1 ~ *.mkv/.*mp4/.*avi inside the task and it's working perfectly. You can't put like  /filepath/*.mp3 in the profile configuration. It doesn't work. The filepath in the profile configuration doesn't accept wildcard *. And by the way, I am on POCO X2 MIUI 12.5.7. Permission: full storage access.
Reply all
Reply to author
Forward
0 new messages