Capture Current App

970 views
Skip to first unread message

Wilson Omesiete

unread,
Aug 8, 2013, 7:28:09 PM8/8/13
to tas...@googlegroups.com
Is it possible to set the current foreground app to a variable? I saw a few comments like this one that suggest that we might not be able to do this yet.

Rich D

unread,
Aug 8, 2013, 7:41:17 PM8/8/13
to tas...@googlegroups.com

> Is it possible to set the current foreground app to a variable? I saw a few comments like this one that suggest that we might not be able to do this yet.
>

Most foreground apps will have a window value... check out the user guide / variables / window value.   %WIN.   You need tasker selected in your android accessibility settings for it to work...

Wilson Omesiete

unread,
Aug 8, 2013, 9:28:35 PM8/8/13
to tas...@googlegroups.com
Thank you for the suggestion.

I see that I could capture it using a 'New Window' event context and saving the %WIN variable, and this seems to work perfectly in tests. I don't have any experience with Android, but I have a decent amount working with other languages, and I feel like this is could be vulnerable if applied broadly.

Is it possible to look up the actual name of the app based on the window name and then pass it to the 'Kill App' action? 

On an unrelated topic, is there a reference for the proper XML syntax for tasks? It would be nice to possibly make them with a text editor and then import.

Also, tasks that I export are invisible to the import. I can see them with a file browser, but not in Tasker's import, how might I fix this?

Wilson Omesiete

unread,
Aug 8, 2013, 9:32:16 PM8/8/13
to tas...@googlegroups.com
Import problem solved here.
Message has been deleted
Message has been deleted

Wilson Omesiete

unread,
Aug 9, 2013, 5:18:16 AM8/9/13
to tas...@googlegroups.com
I figured this out and used it to make a task to kill whatever the current foreground app is.

Kill Current App (8)
A1: Run Shell [ Command:dumpsys window windows | grep -E 'mCurrentFocus' Timeout (Seconds):0 Use Root:On Store Output In:%rawdump Store Errors In: Store Result In: ] 
A2: Variable Search Replace [ Variable:%rawdump Search:\S+\. Ignore Case:Off Multi-Line:Off One Match Only:Off Store Matches In:%rawdump Replace Matches:On Replace With: ] 
A3: Variable Split [ Name:%rawdump1 Splitter:/ Delete Base:Off ] 
A4: Variable Set [ Name:%CURRENTAPP To:%rawdump11 Do Maths:Off Append:Off ] 
A5: Run Shell [ Command:am force-stop %CURRENTAPP Timeout (Seconds):0 Use Root:On Store Output In: Store Errors In: Store Result In: ] 
A6: Flash [ Text:%CURRENTAPP Killed Long:Off ] 
A7: Stop [ With Error:Off Task: ] 

I am sure that somebody else could do the Regex/string parsing part better, I am terrible at that. I also think that I should add some safety features like maybe a confirmation dialog or something.

I am trying to replicate the "hold back to kill" feature on a few roms for general use. Right now I am using the Bluetooth toggle as the trigger, but I will try to get combo long press of menu and back button working later if it is possible. I'm guessing that checks for variable changes and some check for time since the first variable changed to whether or not it's changed back with another check for the second button being long pressed would work. Is it possible to catch hardware buttons other than the camera and search at all? I have  GS3, so long back is being used by multi-window and I don't have camera or search buttons. Does anyone have other ideas for a trigger?

If buttons can't be used I guess a gesture could be the trigger.
Kill_Current_App.tsk.xml

Rich D

unread,
Aug 9, 2013, 4:38:58 PM8/9/13
to tas...@googlegroups.com

>
> If buttons can't be used I guess a gesture could be the trigger.

I'm guessing a notification click would not suit your needs?

TomL

unread,
Aug 9, 2013, 4:42:56 PM8/9/13
to tas...@googlegroups.com
Why do you need to kill the foreground app?  Why not just use the Tasker action: "Go Home" which should push the foreground app into the background.  Once in the background, Android OS will kill it as needed.

Tom



On Thursday, August 8, 2013 9:28:35 PM UTC-4, Wilson Omesiete wrote:

Wilson Omesiete

unread,
Aug 9, 2013, 5:45:37 PM8/9/13
to tas...@googlegroups.com
A notification click would unfortunately not always work, because some apps hide the taskbar, but thank you I hadn't thought of that.

I am trying to replicate the "hold back to kill" feature on a few roms for general use. Apps malfunction occasionally, and in some cases you need to go to the task manager and force close. This expedites that process assuming I can figure out a convenient trigger.

Rich D

unread,
Aug 9, 2013, 5:51:22 PM8/9/13
to tas...@googlegroups.com

>
> A notification click would unfortunately not always work, because some apps hide the taskbar, but thank you I hadn't thought of that.

DOH.... That was a bad suggestion anyway, I had forgotten the window value changes When the notification is pulled down..  :(

Rich D

unread,
Aug 9, 2013, 8:03:51 PM8/9/13
to tas...@googlegroups.com

Does anyone have other ideas for a trigger?

This might work..

If you have a context monitor for the recent apps window ( it is Recent on my device) and show a small scene button when the recent apps list is displayed. If the button is pressed then with the next window change ( which would be the app you want to kill selected from the recent apps) kill that app..

So you would

1. long press home to get recent apps list.
2. Hit button from scene
3. Select app you want to kill
4. Tasker kills app

Wilson

unread,
Aug 9, 2013, 8:37:25 PM8/9/13
to tas...@googlegroups.com
That sounds like a great idea, and that would significantly cut down the risk of accidentally killing an app.

I am starting to like the thought of shaking my phone like a madman any time an app needs to die, but I am going to remember your idea if I want to change that, and for any other task that I want to activate from anywhere. Adding a scene to the recent apps window could make the home button long press analogous to a consistent right click context menu from anywhere.

Rich D

unread,
Aug 9, 2013, 8:49:23 PM8/9/13
to tas...@googlegroups.com

> I am starting to like the thought of shaking my phone like a madman any time an app needs to die,

I believe a context constantly  monitoring for shake might be hard on the battery...

Wilson

unread,
Aug 9, 2013, 9:53:17 PM8/9/13
to tas...@googlegroups.com
That's a good point. Unfortunately it looks like either the transparent GS3 recent apps list does not count as a window, or I am doing something wrong, because it does not trigger 'New Window' contexts, so your suggestion won't work for me specifically.

Using the list here and 'input keyevent #' from a Run Shell task, it looks like we can emulate literally any key press. That doesn't really help with this in any obvious way, but it might be useful later.

I could add a check for silent mode as well, that way it will only be monitoring for shakes after I change to silent (usually use vibrate).

Rich D

unread,
Aug 10, 2013, 7:30:56 AM8/10/13
to tas...@googlegroups.com

Unfortunately it looks like either the transparent GS3 recent apps list does not count as a window,

Well that is unfortunate,  I assume you have seen other window values and have selected tasker in your android accessibility settings?

This is a profile I use to help figure the %WIN values

Profile: Win Changed (375)
Event: Variable Set [ Variable:%WIN Value:* ]
Enter: Anon (376)
A1: Flash [ Text:%WIN Long:Off ]
A2: Variable Set [ Name:%Awin To:%WIN, Do Maths:Off Append:On ]

That way you can check the %Awin in the variables to get exact spelling.

Brandon Horwath

unread,
Aug 10, 2013, 1:04:53 PM8/10/13
to tas...@googlegroups.com
I believe a context constantly monitoring for shake might be hard on the battery...

Actually, that is how I switch from full intensity (shake quickly in/out), to low intensity (shake quickly side to side) and monitoring for that hardly affects the battery on my device. Just FYI, if you wanted to try it :-)

Wilson

unread,
Aug 12, 2013, 4:24:57 PM8/12/13
to tas...@googlegroups.com
I have noticed much battery loss from the shake monitoring.

Unfortunately it looks like the sensor in my phone is glitched somehow, because I get near constant activation of the shake event even with both 'very high' settings.

Bob Hansen

unread,
Aug 12, 2013, 4:43:32 PM8/12/13
to tas...@googlegroups.com
If it is too sensitive, you need to set to "very low". That's the least sensitive setting. That's what I found worked best.

Wilson

unread,
Aug 12, 2013, 4:48:24 PM8/12/13
to tas...@googlegroups.com
Wow I should work on my reading comprehension. Thank you, swapping those solved the issue.
I'm still trying to avoid using gestures altogether, though.

Rich D

unread,
Aug 12, 2013, 5:11:56 PM8/12/13
to tas...@googlegroups.com

> I'm still trying to avoid using gestures altogether, though.

Starting to run low on ideas ... I Have not been able to find a way to get the last app info or recent app info. It might be in the dumpsys but I could not locate it. Without that ability I would think you might have to keep your own recent app list with a context that records the windows value on every change and then from your home screen you could have a task cut that opens a menu scene with a list of recent apps that you could select one to kill. 

Probably not what you are looking for.....   :(

Ryan Wilson

unread,
Jan 18, 2014, 9:14:47 PM1/18/14
to tas...@googlegroups.com
Anyway to make this Profile to not kill certain apps!
Reply all
Reply to author
Forward
0 new messages