Tasker doesn't recognize a background app. need a work around

4,143 views
Skip to first unread message

xpbr2000

unread,
Jun 28, 2012, 4:15:49 PM6/28/12
to tas...@googlegroups.com
Hello, 

I need to have my LTE turned off while i'm on my IRC app at work. My building get low lte signal and sometimes it will switch to LTE. it will disconnect me form the IRC server every time. 

I've tried to have the context  @ work (location) and Application -AndroIRC. Since my Rom doesn't support LTE toggle i just have it open the mobile data settings on the enter task and the exit task when i'm done using AndroIRC. the problem is it only recognizes the app while it is opened and not that its running in the background and on the ongoing notifications. basically every time i open the app it will pull up the settings screen and also when i close the settings it tries to open it back up because I've returned  AndroIRC what kind of work around is there. or is  there a way to have Tasker recognize when com.androirc is running? I've been looking in the guide haven't found anything use to my situation.


Thanks, 

-Dustin

Walter Francis

unread,
Jul 2, 2012, 3:20:47 PM7/2/12
to tas...@googlegroups.com

Here's an example of how I handle this, hopefully it will be useful for you.  My example is a profile that's running while I'm running GPS/Car Navigation type apps in the car.  Same as you, I want this profile to remain active regardless of foreground app, but initiated by a foreground app.  So here's a summary of my Profiles and Tasks associated

Profile:  If on AC and Running GPS App(s), run anonymous task
 - Task:  Set CAR_GPS = 1

Profile:  If CAR_GPS = 1, run Car GPS Task

Profile:  If on AC, entry task does stuff, but Exit task:
 - Exit Task:  Set CAR_GPS = 0

This way no matter how I'm in and out of the apps that I have associated with my "GPS" profile, as long as AC is connected (plugged into car power) and one of those apps was ran, until I unplug AC, that profile will remain active.

So, don't know how your profile/tasks are organized, but hope the above helps.  :)

Thanks, 

-Dustin

TomL

unread,
Jan 17, 2013, 10:36:49 AM1/17/13
to tas...@googlegroups.com
We started a discussion about this in the Tasker Pro forum:


I think the best way we found was to look in the file /proc/[pid]/oom_adj and decide based on the value whether the process was foreground or background or cached.

The tricky part is that the oom_adj number varies from phone to phone.  You may need to manually collect some oom_adj values and see what the correlation is.

Tom


On Thursday, January 17, 2013 9:38:48 AM UTC-5, oneerleft wrote:
Unfortunately pgrep does not differ between running and (inactive) cached processes. Do you know how to distinguish? 

I do not want to turn off GPS for sport tracking app when it is running in background, but when app is in cache it is ok to turn off. 

Maybe something similar to pgrep (for processes) but for services exists? 

On Sunday, 15 July 2012 22:53:28 UTC+2, Tim wrote:
I'm new to Android but I wanted to achieve a similar function and I figured out how to do it - after some googling... so I figured I'd share.

I installed "Secure Settings" and by using the plugin in Tasker I set the pid of the application (pgrep <appname>) to a variable I can then "Test" against it in Tasker on both Enter and Exit to control what gets turned on or off.



Dave White

unread,
Jan 17, 2013, 11:43:23 AM1/17/13
to tas...@googlegroups.com
I've used a workaround of running a shell script on a loop to detect if the app is in the background. Posted in another thread:

me (Dave White change
Post reply
More message actions
10/22/12
For the shell script, you are basically testing to see whether the app is running in the foreground/background or if it is closed/cached.

Run this shell script, where <app name> is the name of the app (com.whatever.musicplayer or whatever it is for the app you want to test):

cat /proc//$(pidof <app name>)/oom_adj

Store the result to a variable. If the value is 0 then the app is running in the foreground, if it's 1 or 2 then the app is running in the background. If it's greater than 2 then it's no longer running (cached). You'll have to test the oom_adj values on your device. You will need to be rooted for this to work.

Might be annoying to test all of your apps this way, but I use this on a 5 min loop upon exiting Poweramp to toggle between Poweramp's lockscreen and WidgetLocker.


TomL

unread,
Jan 17, 2013, 12:06:34 PM1/17/13
to tas...@googlegroups.com
Awesome, I can't believe I didn't see these posts sooner.  And this method is possible without root too.  You can do this (awkwardly, but possible) using only cat  and ps.

Tom

Rick Macdonald

unread,
Jan 17, 2013, 12:44:48 PM1/17/13
to tas...@googlegroups.com
Tom - you've been helping me today in another thread I started, but this thread is exactly what I am trying to do. Without root, I want to get the value of /proc/PID/oom_adj which tells me if the app is running or cached. I had figured out that much already. I thought I could access grep from Tasker (kbox, etc) but here you mention only cat and ps. What is the awkward method? Try to parse the full ps output in Tasker without having grep to pull out the app's info first?

Rick

TomL

unread,
Jan 17, 2013, 12:56:38 PM1/17/13
to tas...@googlegroups.com
Yes, that's it exactly.  Without grep or awk, you gotta parse it the hard way through Tasker. So, in a nutshell:

pm list packages

... to get the list of possible package names, as package names differ from app names.  Parse using Tasker for the the package name for the app you want.  You'll only have to do this once, probably.

ps [packagename]

... to get the list of matching processes.  Parse in Tasker for the pid column.

cat /proc/{PID}/oom_adj

... to get the oom_adj value.

Tom

Dave White

unread,
Jan 17, 2013, 1:02:41 PM1/17/13
to tas...@googlegroups.com
If the app is running, can you not get the process name from the Applications Manager (Running -> Show Cached Processes -> App in question)? I think it shows it at the bottom of the process screen. Might be easier than parsing from all the package names.

Dave White

unread,
Jan 17, 2013, 1:06:35 PM1/17/13
to tas...@googlegroups.com
Just checked, you don't need to go to cached processes, just Running, and it'll show the process name at the bottom.

Rick Macdonald

unread,
Jan 17, 2013, 1:30:35 PM1/17/13
to tas...@googlegroups.com
Thanks Tom and Dave!

Oh, as Dave says the package name is in the running list. I had found it already by scrolling through the very long output of ps. It's nice to know about the "pm list" command though.

Tom - I can't get "ps [packagename]" or "ps -C packagename" as it would be in Linux, to work. Did you mean that literally? If that prints out one line it does what I would use the elusive "grep" for, and save me parsing the entire long output of ps to find the line with my package name. I'm running these commands manually in Terminal Emulator at the moment, before trying to run them from Tasker.

Rick

TomL

unread,
Jan 17, 2013, 1:51:23 PM1/17/13
to tas...@googlegroups.com
I had to experiment a bit.  Here's what I get:

ps

... shows all processes, system and user.

ps a

... seems to show some processes that start with the letter a, and some that do not!  The behavior seems inconsistent to me.  

You may need to Tasker parse the full output of ps, just to be sure to catch what you're looking for.

Tom

Rick Macdonald

unread,
Jan 17, 2013, 2:10:05 PM1/17/13
to tas...@googlegroups.com

Ah, ok. The "a" is a regular ps option which sort of means "not just my own processes". "ps r" shows running tasks, etc. See "man ps" (or google!).

"ps -C name" is what we want. It will select process running "name" but it didn't work when I tried it with the package name as shown in the full ps output. I see now it works with a full path to the app name, so I just have to find (maybe) the file location of the app. I'm off now searching for com.scs.full.superlink, but of course I don't have "find"...

Rick

TomL

unread,
Jan 17, 2013, 2:19:22 PM1/17/13
to tas...@googlegroups.com
It's probably in /data/app, but without root, you'll be stumbling blind.

Try this:

pm list packages -f superlink

Tom

Rick Macdonald

unread,
Jan 17, 2013, 2:52:56 PM1/17/13
to tas...@googlegroups.com
Yes, without root /data appears empty to me.

The pm command pointed me to /mnt/asec/com.scs.full.superlink-2, which contains pkg.apk and res.zip. I don't know yet what an "android app" really is. Maybe there's nothing on the ps command line that will pull out the line I want if the package name isn't an executable file.

This works:

ps -C /system/bin/at_distributor

but so does this (to find at_distributor):

ps at

"ps com.sec.phone", works, with or without -C.

Nothing seems to be able to find jackpal.androidterminal, which is what I'm running to execute these ps commands. It shows up in the full ps output (as does superlink, which is in the background).

I guess I'll go parse the entire ps output for now.

Rick

Rick Macdonald

unread,
Jan 17, 2013, 5:06:22 PM1/17/13
to tas...@googlegroups.com

Finally, a breakthrough.

Parsing the entire ps output took 35 seconds on my first attempt. I went back and snooped in /proc/PID and found that the command name known to the system is not com.scs.full.superlink, but just .full.superlink.

"ps .full.superlink" returns just my process, as does "ps .fu" or any substring. "ps ." returns half a dozen or so processes.

So, having an reasonable way to get the PID, /proc/PID/oom_adj can be used. On my phone, 2 seems to be sleeping/background. I've seen both 9 and 12 for what should be cached. I assume 0 and/or 1 is actually running in the foreground. With that, one should be able to detect background and running processes.

Regards,
Rick

Rick Macdonald

unread,
Jan 17, 2013, 8:03:33 PM1/17/13
to tas...@googlegroups.com
Some more info.

The command name for ps looks to be the last 15 characters of the package name.

I've only looked at 2 apps, but for oom_adj, when moved away from foreground, one was 2 and the other 10. Both were 9 after actually quitting the app.

Rick

Harald

unread,
Jan 18, 2013, 3:16:52 AM1/18/13
to tas...@googlegroups.com
Thank you very much - this did the job for me. I created the task Endo GPS based on your input. 
The task executd as entry and exit task for Endomondo and it toggles the Use GPS satellites setting.
Please see below: 
Endo GPS (8)
A1: Variable Clear [ Name:%ENDO_CAT Pattern Matching:Off ] 
A2: Secure Settings [ Configuration:cat Package:com.intangibleobject.securesettings.plugin Name:Secure Settings ] 
A3: Wait Until [ MS:1 Seconds:0 Minutes:0 Hours:0 Days:0 ] If [ %ENDO_CAT Is Set ]
A4: If [ %ENDO_CAT < 3 ]
A5: Flash [ Text:GPS enabled Long:Off ] 
A6: GPS [ Set:On ] 
A7: Else 
A8: Flash [ Text:GPS disabled Long:Off ] 
A9: GPS [ Set:Off ] 
A10: End If 
For Secure settings I use Run Command with cat /proc/$(pgrep com.endomondo.android.pro)/oom_adj and write the output to %ENDO_CAT. 
This task can possible be refined a bit. In the future I want to disable the lockscreen in the future additionally. 

But thanks a lot guys! /Harald
PS I am new to this forum and hope posting task contents is ok. 

Rick Macdonald

unread,
Jan 18, 2013, 6:05:21 PM1/18/13
to tas...@googlegroups.com


I couldn't get something simple like this to work. If I switch away form the GPS program (Navionics Marine) with the home button, it generates exit and enter events and the GPS turns on and off. Well, on Android 4 it can't do that so I have to pop up the Setting dialog which I don't want to see every time I look at something else on the phone. Doesn't the same happen to you?

I assume pgrep is only available on a rooted phone?

Rick

TomL

unread,
Jan 18, 2013, 7:27:43 PM1/18/13
to tas...@googlegroups.com
profile ActivateGps
on context app YourNavApp
enter task actions:
stop if %GPS matches on [because if already on, nothing left to do]
open dialog settings > gps & network location
stop

exit task actions
stop if %GPS matches off [because if already off, nothing to do]
run shell > ps YourNavAppPkg , set var %res to output
parse %res for pid, store in %pid
run shell > cat /proc/%pid/oom_adj , set var %oomadj to output
stop if %oomadj > 6 [threshhold for background app? need to tweak? ]
open dialog settings > gps & network location
stop

Tom

Rick Macdonald

unread,
Jan 19, 2013, 1:08:03 PM1/19/13
to tas...@googlegroups.com


Thanks, Tom. That's subtly different from what I had, but does work better.

The only remaining problem is that if I don't turn the GPS on when entering and getting the settings dialog, it gets stuck in an enter/exit loop showing the setting dialog every time. (Other nav programs may not have this problem.) That's OK though, since the idea is usually to turn it on. If I don't want it on, I have to turn it off again after I'm in the program. Wanting to leave it OFF after setting up this profile just to turn it ON is not as lame as it seems. One is often sitting at anchor or here at home pre-planning and marking routes on the map. You don't want the GPS on then.

The biggest reason for the profile is to turn it OFF when exiting, which does work well. One can easily forget and leave it on, causing battery drain issues.

I temporarily had the exit task "say" the %oomadj value to find what it is. For my nav program it's 7 if I switch away to look at txt messages, etc. When I quit the nav program, it's 9.

Rick

Dave White

unread,
Jan 20, 2013, 1:51:14 PM1/20/13
to tas...@googlegroups.com
Having a bit of trouble following... Is this a method for getting the oom_adj value without root? If so, might be worthy of a seperate thread with a walkthrough. I know it's definitely a requested feature (background processes anyway).

TomL

unread,
Jan 20, 2013, 4:01:11 PM1/20/13
to tas...@googlegroups.com
Yes, it is indeed a method for getting the oom_adj value for any process, without needing root or busybox or secure settings.

Rick hashed out the nitty gritty details, look through this thread for his posts on how he did it.

Tom

TomL

unread,
Jan 20, 2013, 4:03:02 PM1/20/13
to tas...@googlegroups.com
Rick, if you long click on the profile entry, you'll have access to profile settings.. One setting is Cooldown time, which is an amount of time you can set to prevent the profile from reactivating again.

You might try a cooldown time of a minute or so, that should prevent the endless looping you described.

Tom

TomL

unread,
Jan 20, 2013, 4:15:18 PM1/20/13
to tas...@googlegroups.com
I'll summarize the oom_adj techinque in a new thread in a few days.

But to summarize here:

To detect when an app in in background, run that app (like Google Navigation, with a destination) and then let it go to to background ( like by opening a terminal emulator app).

Run the shell command "ps" and look through the displayed processes to find that app's process. Note that an app's name may differ from the package name. From the ps listing, find the process id (PID).

Run the command "cat /proc/PID/oom_adj", replacing PID with the actual process id. in return, you'll get back a number, ranging from as low as -17 to as high as 17. An app running in the Foreground tend to have an oom_adj score of 1 or 0 or maybe even lower. An app in Background may have a score of 2 or 3 or higher.

The shell commands ps and cat should be available on stock unrooted phones.

Tom

Rick Macdonald

unread,
Jan 21, 2013, 10:47:56 PM1/21/13
to tas...@googlegroups.com


That prevents the endless loop at startup, but then later I get the GPS settings dialog again when I return to the program after looking at a text message.

Rick

TomL

unread,
Jan 22, 2013, 7:58:47 AM1/22/13
to tas...@googlegroups.com
Rick, you might try turning on Tasker's Run Log feature (Menu > More > Run Log > On/Off) and try to recreate the problem behavior.  One suggestion.  If you have other Tasker profiles unrelated to this GPS Nav app defined, I'd turn them off first before turning on the Run Log.  It can get messy in the log with too many profiles logging.

Another suggestion is to sprinkle notification alert actions through out the tasks to get real-time feedback for what's going on.  Note that notifications will overwrite older notifications if that have the exact same title.  I like to append %TIMEMS to my notification titles, so that they are more likely to be unique, such as:

Alert > Notify > "Nav app in bg, oom_adj = %oom_adj . %TIMEMS"

Hope this helps.

Tom

Rick Macdonald

unread,
Jan 22, 2013, 6:11:18 PM1/22/13
to tas...@googlegroups.com


Thanks, Tom.

I do have notifications in my tasks using "say". What I find is that oom_adj is consistently 9 when apps (at least the 2 I'm playing with) are actually exited. Otherwise, it's 2 for one app and 7 for the other when I just switch away and it's still "running".

I think it's all behaving correctly. The nav app generates exit and enter events every time I switch away. Assuming that is correct tasker behavior then there isn't a problem to troubleshoot. I thought of 2 easy ways to fix it:

1) replace the app's icon/launcher with a tasker shortcut that shows the GPS settings before launching the app.
2) set a flag in my task upon entering and showing the GPS settings, but don't show them if the flag is already set. Then, clear the flag only when the exit task finds oom_adj == 9.

I think I'll go with #2.

Rick

GermainZ

unread,
Jan 22, 2013, 6:22:14 PM1/22/13
to tas...@googlegroups.com
This is worth mentioning if you flash ROMs frequently, or if you're planning on sharing your projects.
oom_adj's default values are modified by some memory management apps/scripts, for example, the awesome V6 Supercharger by zeppelinrox.

You can fetch the default values instead (check zep's script; I would do it but I don't have time right now).

TomL

unread,
Jan 22, 2013, 8:01:05 PM1/22/13
to tas...@googlegroups.com
I don't personally use SuperCharger, but one way to get the os default oom_adj threshholds is with the shell cmd:

getprop | grep "_APP_ADJ"

Tom

David Cross

unread,
Feb 18, 2013, 3:19:11 PM2/18/13
to tas...@googlegroups.com
Hello All,

So I'm new to Tasker and I have no idea what PS and all the other functions are that you;re using or even how to access them or run them.

Going forward newbies and novicies need an "easy" way to enable this function.  For example when I select an App a configuration option should say "foreground", "background", "both" and then Tasker does whatever it needs in the background to enable fore\background monitoring of a running app.

Is this something the devs are going to work towards?

Regards, David.

On Thursday, June 28, 2012 9:15:49 PM UTC+1, Xpbr2000 wrote:
Hello, 

I need to have my LTE turned off while i'm on my IRC app at work. My building get low lte signal and sometimes it will switch to LTE. it will disconnect me form the IRC server every time. 

I've tried to have the context  @ work (location) and Application -AndroIRC. Since my Rom doesn't support LTE toggle i just have it open the mobile data settings on the enter task and the exit task when i'm done using AndroIRC. the problem is it only recognizes the app while it is opened and not that its running in the background and on the ongoing notifications. basically every time i open the app it will pull up the settings screen and also when i close the settings it tries to open it back up because I've returned  AndroIRC what kind of work around is there. or is  there a way to have Tasker recognize when com.androirc is running? I've been looking in the guide haven't found anything use to my situation.


Thanks, 

-Dustin

TomL

unread,
Feb 18, 2013, 3:52:29 PM2/18/13
to tas...@googlegroups.com
There's one dev (Pent). I don't know if fore/background process detection is on his todo list. The todo list is massive, by the way.

Tom

Rich D

unread,
Feb 18, 2013, 4:04:01 PM2/18/13
to tas...@googlegroups.com

> There's one dev (Pent).  I don't know if fore/background process detection is on his todo list.  The todo list is massive, by the way.

Yep.. It's there.

Item number 16,531---- running background service detection

Just kidding about the item number :) But it is a rather large list.  The list is on the tasker main website Under "Plans"

Rich..

Harald

unread,
Feb 20, 2013, 5:25:02 AM2/20/13
to tas...@googlegroups.com
I created this small "help task" which can easily be accessed: 

App Running?
A1: Run Shell [ Command:cat /proc/$(pgrep %par1$)/oom_adj Timeout (Seconds):0 Use Root:Off Store Result In:%oomadj ] 
A2: Flash [ Text:Oom_adj for %par1 is %oomadj Long:Off ] 
A3: Return [ Value:1 Stop:On ] If [ %oomadj ~ 0/2 ]
A4: Return [ Value:0 Stop:Off ] 

Please note 
1. the second $ in the shell command; this is for limiting the query to exact matches. Some apps run multiple processes (services?) as for example the app Endomondo Pro sometimes will run com.endomondo.android.pro:Synchronize (if I remember correctly). We are only interested in the main process (service?) here. 
2. if the process is not running %oomadj will be empty but the task returns 0 anyway. 

App Running? can easily be accessed from another task as shown below: 

Test App Running
A1: Perform Task [ Name:App Running? Stop:Off Priority:5 Parameter 1 (%par1):com.android.music Parameter 2 (%par2): Return Value Variable:%apprun ] 
A2: Wait Until [ MS:250 Seconds:0 Minutes:0 Hours:0 Days:0 ] If [ %apprun Is Set ]
A3: Flash [ Text:%apprun Long:Off ] 

Here the trick is to use Wait Until to ensure everything is running in the correct order. 

The only issue left is to find the correct process name. In Test App Running, I used the process name for the android music app com.android.music. The name was found by starting the music app and checking Settings>Applications>Running Services. 

Good luck! 

Rich D

unread,
Feb 20, 2013, 8:57:49 AM2/20/13
to tas...@googlegroups.com

Wow, great work.. This will be very helpful ..

Rich..

TaskerAholic

unread,
Apr 11, 2013, 7:16:48 PM4/11/13
to tas...@googlegroups.com
The flash action always show "Oom_adj for com.android.music is 1", no matter it is played or not.

As a result, it return "0"

Do you guess why?

jake london

unread,
May 3, 2013, 9:43:02 PM5/3/13
to tas...@googlegroups.com
Would you be willing to share this? I also user the ulysses speedo app in conjunction with the car panel app on my droid inc. I'm trying to figure out a way to exit the car panel app when I exit the speedo app (but not when I switch away from the speedo app while it's running to make a call, adjust music, etc.).

JL

On Tuesday, January 29, 2013 3:57:39 AM UTC-8, Nigel Rudgley wrote:
Some great info on here - thanks all.

I've just used this to implement a profile change when I'm in my car app (ulysses speedo). Pretty much cloned Harald's task and assigned it to the entry/exit task for a profile which checks for the app.

Its a bit messy, as it tends to try and set the car profile a few times when I flip between the speedo and nav/music apps, but this could be easily fixed with a variable.

Vladimir Spasic

unread,
May 8, 2013, 4:33:41 AM5/8/13
to tas...@googlegroups.com
Can someone who has made a profile with this guide to publish here?
I do not understand much, but if I see a concrete example, I'll understand
any profile, any application....

GermainZ

unread,
May 8, 2013, 4:44:16 AM5/8/13
to tas...@googlegroups.com
The post you quoted is a Task's description. Just recreate it.

Vladimir Spasic

unread,
May 8, 2013, 5:36:06 PM5/8/13
to tas...@googlegroups.com
Ras (39)
A1: Run Shell [ Command:cat/proc/$(pgrep %par1$)/oom_adj Timeout (Seconds):0 Use Root:Off Store Output In: Store Errors In: Store Result In:%OOMADJ ]
A2: Flash [ Text:Oom_adj for %par1 is %OOMADJ Long:Off ]
A3: Return [ Value:1 Stop:On ] If [ %OOMADJ ~ 0/2 ]

A4: Return [ Value:0 Stop:Off ]


Ap (44)
A1: Perform Task [ Name:Ras Stop:Off Priority:5 Parameter 1 (%par1):com.skype.raider Parameter 2 (%par2): Return Value Variable:%APPRUN ]
A2: Wait Until [ MS:250 Seconds:0 Minutes:0 Hours:0 Days:0 ] If [ %APPRUN Is Set ]
A3: Flash [ Text:%APPRUN Long:Off ]
try create this but don't work

GermainZ

unread,
May 8, 2013, 5:43:35 PM5/8/13
to tas...@googlegroups.com
Explain "don't work". Do you get an error message? Which one? Did you check Tasker's logs to make sure the shell command is executing successfully? Are butterflies flying out of your phone? Is that a missing space in A1 between 'cat' and '/proc'? Did you try to add some Flash actions to see what's going wrong and where?

Should I go on?

Vladimir Spasic

unread,
May 8, 2013, 6:21:13 PM5/8/13
to tas...@googlegroups.com
Thanks man, the problem was space " Is that a missing space in A1 between 'cat' and '/proc'?" Now work.

GermainZ

unread,
May 8, 2013, 6:24:42 PM5/8/13
to tas...@googlegroups.com
Glad you got it working. I was afraid butterflies were flying out of your phone. :P

jake london

unread,
May 9, 2013, 8:09:27 PM5/9/13
to tas...@googlegroups.com
Can't get this to work. When I look at the Tasker log it indicates
that the Run Shell Step is failing. I'm a novice around this stuff. So
pilot error is entirely possible. I'm on a rooted droid inc running
gingerbread.

Am I right in assuming that I should be doing this for A1: of the App
Running Task:

1. Select Run Shell action
2. Insert the following text in the Command box: cat /proc/$(pgrep
%par1$)/oom_adj
3. Make sure use root is not checked
4. Put the following in the Store Result In box: %oomadj

Fwiw, when I run "cat /proc/$(pgrep %par1$)/oom_adj " in my terminal
emulator on the phone I get the message "No such file or directory."

JL
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Tasker" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/tasker/HqBGTsmwvsw/unsubscribe?hl=en.
> To unsubscribe from this group and all its topics, send an email to
> tasker+un...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
Message has been deleted

TomL

unread,
May 9, 2013, 9:11:02 PM5/9/13
to tas...@googlegroups.com
You should first trouble shoot it in parts from your terminal app. First let's find the process name of the app you're interested in. Let's say it's a music app (called "MyMusic") running in the background. Type in the terminal app:

ps

You should see a flood of processes. Let's narrow it down to just the line we want:

ps | grep -i MyMusic

Hopefully that works and produces one row. You can also try this command:

pgrep MyMusic

to return the process id (pid) of MyMusic. If that worked, (let's say the pid was 1234), you can type this:

cat /proc/1234/oom_adj

That should return a number. If that worked, you can do all of the above in one step in the shell like this:

cat /proc/$(pgrep MyMusic)/oom_adj

If that works, then you can put that into Tasker's run shell action like this:

RunShell > Command:
cat /proc/$(pgrep MyMusic)/oom_adj
Store Output in Variable: %ShellOutput

The returning answer will get stored in the var %ShellOutput

I hope that helps.

Tom

jake london

unread,
May 9, 2013, 9:13:45 PM5/9/13
to tas...@googlegroups.com
Yes, it does. It was "%par1$" in the example that confused me. I
didn't realize I was supposed to put my process name in there.

Thanks. I will troubleshoot further.

JL

TomL

unread,
May 9, 2013, 9:23:58 PM5/9/13
to tas...@googlegroups.com
Look in the Tasker userguide in the section about the action PerformTask to learn more about %par1.

Let's say you have an Task defined called DoubleIt that would calculate for you the sum of a number with itself. If you wanted to run DoubleIt on the number 5, you can call it with the action:

Task > PerformTask > Task: DoubleIt
Parameter1: 5
Return: %TheAnswer

Alert > Notify > Title: double of 5 is %TheAnswer

The Task DoubleIt would look like this:

set Variable > name: %doubled
value: %par1 * 2
do maths: Yes

task > return > value: %doubled

Tom

jake london

unread,
May 9, 2013, 9:29:51 PM5/9/13
to tas...@googlegroups.com
So if I put the PID for Ulyesses Speedometer into this command I get a number:

cat /proc/1234/oom_adj

I got the PID by manually scanning the output of the ps command.

But the grep commands don't seem to work for me.

the name associated with the PID is com.binarytoys.speedometerpro

But doing either of the grep command or the pgrep command on that name
doesn't find anything.

JL

On Thu, May 9, 2013 at 6:11 PM, TomL <toml...@gmail.com> wrote:

TomL

unread,
May 9, 2013, 9:30:14 PM5/9/13
to tas...@googlegroups.com
Just a quick reminder. In the latest version of Tasker, the RunShell action has three different returning values. Let's say you ran the shell command: echo "hello there"

Output: hello there (the output of the shell command)
Result: 0 (whether or not the command succeeded. 0 means success for result codes)
Error: (nothing, because no error)

Tom

TomL

unread,
May 9, 2013, 9:33:10 PM5/9/13
to tas...@googlegroups.com
Try:

ps | grep speedo

or

pgrep speedo

Anything?

Tom

jake london

unread,
May 9, 2013, 9:35:44 PM5/9/13
to tas...@googlegroups.com
Nope.

TomL

unread,
May 9, 2013, 9:39:48 PM5/9/13
to tas...@googlegroups.com
Try this:

ps | grep -i speedo

Just to be clear, that's:

ps [space] [vertical bar] [space] grep [space] [minus] i [space] speedo

Tom

TomL

unread,
May 9, 2013, 9:46:54 PM5/9/13
to tas...@googlegroups.com
Cut and paste for me the exact command(s) you're typing into the shell, and the exact output or errors you're getting back.

Tom

jake london

unread,
May 10, 2013, 1:03:16 AM5/10/13
to tas...@googlegroups.com

Here's what I get when I enter what you suggested a couple messages back.

$ ps | grep -i speedo
grep: not found
$

JL

On May 9, 2013 6:47 PM, "TomL" <toml...@gmail.com> wrote:
Cut and paste for me the exact command(s) you're typing into the shell, and the exact output or errors you're getting back.

Tom

Bob Hansen

unread,
May 10, 2013, 1:38:24 AM5/10/13
to tas...@googlegroups.com
It appears based on the error, that the grep command is not found?

If you simply enter 'grep' without the quotes and execute it, you should get a listing of the grep command help.
Do you?

jake london

unread,
May 10, 2013, 1:41:20 AM5/10/13
to tas...@googlegroups.com
No. Not getting the list of help.

JL

Matt R

unread,
May 10, 2013, 2:20:36 AM5/10/13
to tas...@googlegroups.com
You need to install busybox. You can find installers in the play store.

Matt

jake london

unread,
May 10, 2013, 2:23:21 AM5/10/13
to tas...@googlegroups.com
Thanks, slowly figuring that out. Thanks for confirming. I've already
got the installer on my phone.

Is there going to be any sort of conflict with the BusyBox that was
installed with Titanium backup? I think that's what kept me from
installing it a while back. Didn't want to muck anything up.

JL

On Thu, May 9, 2013 at 11:20 PM, Matt R <matthew.r...@gmail.com> wrote:
> You need to install busybox. You can find installers in the play store.
>
> Matt
>

jake london

unread,
May 10, 2013, 2:38:15 AM5/10/13
to tas...@googlegroups.com
Busybox install seems to have solved it, at least for now. Thanks for
all the help folks!

JL

TomL

unread,
May 10, 2013, 9:31:18 AM5/10/13
to tas...@googlegroups.com
Oy gevalt. I should have checked that you had those shell commands available first.

Tom

Peleke

unread,
Aug 29, 2013, 4:07:49 AM8/29/13
to tas...@googlegroups.com
I cannot get it to work even if it works in the console.

AppRunning (49)
A1: Run Shell [ Command:cat /proc/$(pgrep %par1$)/oom_adj Timeout (Seconds):0 Use Root:Off Store Output In: Store Errors In: Store Result In:%oomadj ]
A2: Flash [ Text:Oom_adj for %par1 is %oomadj Long:Off ]
A3: Return [ Value:1 Stop:On ] If [ %oomadj ~ 0/2 ]


A4: Return [ Value:0 Stop:Off ]

DetectApp (51)
A1: Perform Task [ Name:AppRunning Stop:Off Priority:5 Parameter 1 (%par1):com.android.music Parameter 2 (%par2): Return Value Variable:%apprun ]
A2: Wait Until [ MS:250 Seconds:0 Minutes:0 Hours:0 Days:0 ] If [ %apprun Is Set ]
A3: Flash [ Text:%apprun Long:Off ]

Have I missed something? I always get an ExitErr for the first Task. Thanks for help

Brandon Horwath

unread,
Aug 29, 2013, 10:06:47 AM8/29/13
to tas...@googlegroups.com
What is the output, result, and/or error results?

Do you have busybox installed?

Peleke

unread,
Aug 29, 2013, 10:15:13 AM8/29/13
to tas...@googlegroups.com
I have no errors when I try these commands manually in the local shell:

ps, ps | grep -i process, pgrep process, cat /proc/1234/oom_adj, cat /proc/$(pgrep process)/oom_adj

The first task I pasted above just stops in Tasker with a "ExitErr" found in the log files, nothing else, no flashing etc.
I don't know how to debug it...
Thanks for help

Dave White

unread,
Aug 29, 2013, 10:17:42 AM8/29/13
to tas...@googlegroups.com
I haven't been keeping up with this thread, but my command reads:

A1: Run Shell [ Command:cat /proc/$(pidof com.maxmpz.audioplayer)/oom_adj Timeout (Seconds):0 Use Root:Off Store Output In:%Poweramp Store Errors In: Store Result In: Continue Task After Error:On ]

I've got pidof instead of pgrep. Maybe try that.

Brandon Horwath

unread,
Aug 29, 2013, 10:53:37 AM8/29/13
to tas...@googlegroups.com
AppRunning (49)
A1: Run Shell [ Command:cat /proc/$(pgrep %par1$)/oom_adj Timeout (Seconds):0 Use Root:Off Store Output In: Store Errors In: Store Result In:%oomadj ]
A2: Flash [ Text:Oom_adj for %par1 is %oomadj Long:Off ]
A3: Return [ Value:1 Stop:On ] If [ %oomadj ~ 0/2 ]

First, oom_adj may not ~ 0/2 EVEN IF IT IS RUNNING or not! You are not matching the correct patterns to determine if the action is successful or not. Research this.

Second, assign a variable to store errors in, something local, and add alert. Flash %somethinglocal if %somethinglocal is set.

That will help you debug.

Also, what are you getting in the results field?

I will ask again, do you have busybox installed?

bdanders

unread,
Aug 29, 2013, 11:14:40 AM8/29/13
to tas...@googlegroups.com
I can confirm that I'm also using 'pidof' and not 'pgrep'. Maybe try using that instead. Also turn on 'Continue Task After Error' and include an error variable. It helps in the debugging process.

A1: Run Shell [ Command:cat /proc//$(pidof %app_name)/oom_adj Timeout (Seconds):10 Use Root:Off Store Output In:%result Store Errors In: Store Result In: Continue Task After Error:On ]

Peleke

unread,
Aug 29, 2013, 11:46:00 AM8/29/13
to tas...@googlegroups.com
It works now, I had only an unknown service name in the second task.

What do you mean by "First, oom_adj may not ~ 0/2 EVEN IF IT IS RUNNING or not!"? I have just copied the script from Harald Arnbak 1:1

One problem left: service keeps running after stopping Spotify.

Another problem: if the service is not running the first task doesn't work, even if I tick the box to go on if there are errors. I cannot see even a flash if I make it the first thing to run!

Dave White

unread,
Aug 29, 2013, 11:50:41 AM8/29/13
to tas...@googlegroups.com
Continue Task After Error:On

You'll get different values based on wetehr it's running in the foreground, background, or not at all. You need to test these values on your own device to see what they are.

Brandon Horwath

unread,
Aug 29, 2013, 12:43:14 PM8/29/13
to tas...@googlegroups.com
You'll get different values based on wetehr it's running in the foreground, background, or not at all. You need to test these values on your own device to see what they are.

Very true! I discovered certain apps on my device have a value of LESS THAN ZERO when running in the foreground. Most devices the oom_adj value will = 1 or 0 while in foreground.

Near as I can tell, this device is the only one I have heard of to generate that value for a foreground app. It appears to have something to do with the processes in use for the activity on my device. For example, I can watch an app run from background to foreground as the value shifts from 10 to 6 to < 2 into foreground.

But, regardless you do need to test this. Something copied from someone else does not guarantee it will work for you, even when it does for them :-)

Kousha

unread,
Apr 3, 2014, 4:57:03 AM4/3/14
to tas...@googlegroups.com
Here's an alternative for "pgrep" for non-rooted phones:

for i in /proc/[0-9]*; do if [[ $(cat "${i}/comm" 2> /dev/null) == "LAST 15 CHARACTERS OF APP NAME" ]]; then echo "${i#/proc/}"; fi; done

Pent

unread,
Apr 3, 2014, 7:46:38 AM4/3/14
to tas...@googlegroups.com
I added a 'Services' flag for the app context for 4.3 (not yet released), for those who just need to know when
a relevant service is running.

Pent

Khaos

unread,
Apr 18, 2014, 8:17:51 AM4/18/14
to tas...@googlegroups.com
Hi,

there is this new extension for Tasker


Regards

Khaos

Am Donnerstag, 28. Juni 2012 22:15:49 UTC+2 schrieb Xpbr2000:
Hello, 

I need to have my LTE turned off while i'm on my IRC app at work. My building get low lte signal and sometimes it will switch to LTE. it will disconnect me form the IRC server every time. 

I've tried to have the context  @ work (location) and Application -AndroIRC. Since my Rom doesn't support LTE toggle i just have it open the mobile data settings on the enter task and the exit task when i'm done using AndroIRC. the problem is it only recognizes the app while it is opened and not that its running in the background and on the ongoing notifications. basically every time i open the app it will pull up the settings screen and also when i close the settings it tries to open it back up because I've returned  AndroIRC what kind of work around is there. or is  there a way to have Tasker recognize when com.androirc is running? I've been looking in the guide haven't found anything use to my situation.


Thanks, 

-Dustin

Zsolt Müller

unread,
Jun 17, 2014, 6:44:15 PM6/17/14
to tas...@googlegroups.com
Works like a charm. :-)
Using Tasker 4.3u4 on CM11 (M7).

Profajl Nejm

unread,
Mar 1, 2015, 11:36:06 AM3/1/15
to tas...@googlegroups.com
I know the thread is pretty old but I thought I should post my findings since I've tried different shell commands the last few hours.

This command worked for me.

Run shell.

type " pgrep -l com.* "  or exact package name if you know it. This command didn't produce any error for me but the output variable was empty if package name wasn't included in the pgrep list.
Reply all
Reply to author
Forward
0 new messages