• PSA: Find recent Android activity from a desktop using adbrecent script

    From Maria Sophia@mariasophia@comprehension.com to comp.mobile.android,alt.os.linux,alt.comp.os.windows-10,comp.sys.mac.system on Fri Nov 13 14:45:53 2026
    From Newsgroup: comp.sys.mac.system

    PSA: Find recent Android activity from a desktop using adbrecent script

    Below is a script I wrote today which tells us, from the desktop,
    the most recent activities which have been run on the Android phone.

    From your desktop, over Wi-Fi (or USB), did you ever want to quickly figure out what recent app or activity just popped up on your screen, only to be drowned in a wall of normal system clutter from launchers, settings, and background services?

    It's useful for debugging (e.g., what app popped *that* up?) and for customization (what privacy settings activity did Google hide 5 levels
    deep that we'd want to create a single-tap desktop shortcut to?).

    To make inspecting recent Android activities clean and painless,
    I wrote a lightweight, zero-dependency adbrecent Windows batch utility.

    It can easily be ported to macOS/Linux if people want to test the port.

    It knows about activities to ignore permanently but it also adds on-the-fly activities to ignore and also can save those temporary activities to ignore
    in an external text file for maximum flexibility in varied work models.

    Replaces some of what Shortcut Widgets (+Inspector) used to do for us.
    <com.cemique.shortcutwidgets>

    Shortcut Inspector was a small, free, ad-free Android utility by developer Hamed Nikbakht that showed the package and activity name of any app screen,
    so we could build one-tap shortcuts to buried settings or to app screens.

    Unfortunately, it's been off the Google Play Store since around August 2023, (though the APK still circulates on mirrors like APKCombo and APKPure).
    Worse, for whatever reasons (unknown to me), it no longer works reliably
    on my Android 13 Galaxy, so I presume something changed over time.

    To replace that missing functionality, I've been using this command:
    adb shell dumpsys activity recents | grep -i "realActivity\|packageName"
    Which was discussed recently on the Android newsgroup in this thread
    Newsgroups: comp.mobile.android
    Subject: How can we accurately easily ID the most recent package that was run?
    Date: Tue, 3 Nov 2026 22:16:04 -0400
    Message-ID: <11ce4h3$2lve$1@nnrp.usenet.blueworldhosting.com>

    The script I wrote below simply runs that command, but adds efficiency improvements in terms of filtering out clutter, either permanently
    (defined inside the script) or on the fly (defined in an external file).

    Here's what it looks like in action...

    adbrecent{enter}
    Fetching recent activities from device...
    [Active Ignore List from adbrecent_ignore.txt:]
    io.github.muntashirakon.AppManager
    com.teslacoilsw.launcher
    com.android.settings
    com.cemique.shortcutwidgets
    ---------------
    realActivity={opencontacts.open.com.opencontacts.debug/opencontacts.open.com.opencontacts.activities.MainActivity}
    realActivity={com.whatsapp/com.whatsapp.Main}
    realActivity={xyz.klinker.messenger/xyz.klinker.messenger.activity.MessengerActivity}
    realActivity={com.safetyapp.b.safe.emergencyapp/com.safetyapp.b.safe.emergencyapp.SplashScreen}
    realActivity={com.runitrut.dailytodoapp/com.runitrut.dailytodoapp.MainActivity}
    realActivity={com.Avenza/com.avenza.rootview.SplashActivity}
    realActivity={com.apkupdater/com.apkupdater.ui.activity.MainActivity}

    -------------------------------------------------------------------------
    Enter package(s) to ignore (or press Enter to exit): com.whatsapp com.Avenza{enter}
    Fetching recent activities from device...
    realActivity={opencontacts.open.com.opencontacts.debug/opencontacts.open.com.opencontacts.activities.MainActivity}
    realActivity={xyz.klinker.messenger/xyz.klinker.messenger.activity.MessengerActivity}
    realActivity={com.safetyapp.b.safe.emergencyapp/com.safetyapp.b.safe.emergencyapp.SplashScreen}
    realActivity={com.runitrut.dailytodoapp/com.runitrut.dailytodoapp.MainActivity}
    realActivity={com.apkupdater/com.apkupdater.ui.activity.MainActivity}
    -------------------------------------------------------------------------
    Enter package(s) to ignore (or press Enter to exit):{enter}
    Save newly ignored packages to adbrecent_ignore.txt?
    Press [Y]es or [N]o: Y{enter}
    Appending new packages to adbrecent_ignore.txt...
    Saved successfully
    -------------------------------------------------------------------------
    Current full contents of adbrecent_ignore.txt:
    -------------------------------------------------------------------------
    io.github.muntashirakon.AppManager
    com.teslacoilsw.launcher
    com.android.settings
    com.cemique.shortcutwidgets
    com.whatsapp
    com.Avenza
    -------------------------------------------------------------------------
    Exiting adbrecent. Goodbye
    Press any key to continue . . .{enter}

    Here's the script, which I wrote today because I was tired of manually filtering out the same activities over and over, where I first wrote
    this for findstring but then switched to grep and back to findstring
    for complete Windows compatibility.

    Since this is such a simple script, I don't think porting is an issue.
    If you want to test it for the team, let me know & I'll port it for you.
    :: -------------------------------------------------------------------------
    :: adbrecent.bat
    :: Fetches recent Android activities and filters out common system apps
    :: Contains internal ignore list and self-maintains external ignore list
    :: -------------------------------------------------------------------------
    :: v2p4 20261113 Displays ignore list on startup for initial transparency
    :: v2p3 20261113 Displays ignore list upon saving only if it was updated
    :: v2p2 20261113 Replaced set /p with choice command for a single enter tap
    :: v2p1 20261113 Fixed buffer lag during loop-to-prompt transition
    :: v2p0 20261113 Added prompt to permanently save session ignores
    :: v1p9 20261113 Updated ignore file support to separate-line format
    :: v1p8 20261113 Added adbrecent_ignore.txt one-line file support
    :: v1p7 20261113 Improved exit checks so single-press Enter exits instantly
    :: v1p6 20261113 Fixed empty-input check so exit works after spaces
    :: v1p5 20261113 Replaced grep with findstr for native Windows compatibility
    :: v1p4 20261113 Added loop to fetch first, prompt for new filters, and exit
    :: v1p3 20261113 Added interactive prompt for additional runtime filters
    :: v1p2 20261113 Added dynamic command-line argument filtering support
    :: v1p1 20261113 Fixed findstr treating parentheses and spaces literally
    :: v1p0 20261113 Lists recent activities but filters out common activities
    :: -------------------------------------------------------------------------
    @echo off
    setlocal enabledelayedexpansion

    :: Initialize dynamic runtime filters tracking variables
    set "dynamic_filters="
    set "new_session_filters="

    :: Check if the ignore file exists.
    :: If not, create a default ignore file with line-by-line entries
    if not exist "adbrecent_ignore.txt" (
    (
    echo io.github.muntashirakon.AppManager
    echo com.teslacoilsw.launcher
    echo com.android.settings
    ) > "adbrecent_ignore.txt"
    )

    :loop
    cls
    echo Fetching recent activities from device...
    echo.

    :: Read baseline filters line-by-line from external file
    :: Pack them into a space-separated string for findstr
    set "base_ignore="
    for /f "usebackq delims=" %%A in ("adbrecent_ignore.txt") do (
    set "base_ignore=!base_ignore! %%A"
    )

    :: Display active baseline ignore list on the first loop iteration
    if "%dynamic_filters%"=="" (
    echo [Active Ignore List from adbrecent_ignore.txt:]
    for /f "usebackq delims=" %%A in ("adbrecent_ignore.txt") do (
    echo %%A
    )
    echo ---------------
    )

    :: -------------------------------------------------------------------------
    :: Fetch recent activities and filter using native findstr pipes with
    :: combined ignore lists (can easily be ported to be cross platform).
    :: -------------------------------------------------------------------------
    adb shell dumpsys activity recents | findstr /i "realActivity packageName" | findstr /v /i "!base_ignore! !dynamic_filters!"

    echo.
    echo -------------------------------------------------------------------------
    :: Completely clear the variable before prompting
    set "new_ignore="
    set /p "new_ignore=Enter package(s) to ignore (or press Enter to exit): "

    :: -------------------------------------------------------------------------
    :: Exit loop for efficiency when Enter is pressed without typing anything
    :: -------------------------------------------------------------------------
    if not defined new_ignore goto prompt_save
    if "%new_ignore%"=="" goto prompt_save

    :: -------------------------------------------------------------------------
    :: Append the new package to the running list of dynamic filters
    :: -------------------------------------------------------------------------
    set "dynamic_filters=!dynamic_filters! %new_ignore%"
    set "new_session_filters=!new_session_filters! %new_ignore%"

    goto loop

    :prompt_save
    :: -------------------------------------------------------------------------
    :: Skip the save prompt for efficiency if no new filters were added
    :: -------------------------------------------------------------------------
    if not defined new_session_filters goto done

    echo.
    echo Save newly ignored packages to adbrecent_ignore.txt?
    :: -------------------------------------------------------------------------
    :: Use native choice command which restricts input to Y or N
    :: and, for efficiency, which reacts instantly on keypress without Enter
    :: -------------------------------------------------------------------------
    choice /c YN /n /m "Press [Y]es or [N]o: "

    if errorlevel 2 goto done
    if errorlevel 1 (
    echo.
    echo Appending new packages to adbrecent_ignore.txt...
    for %%P in (%new_session_filters%) do (
    echo %%P >> "adbrecent_ignore.txt"
    )
    echo Saved successfully!
    echo.
    echo -------------------------------------------------------------------------
    echo Current full contents of adbrecent_ignore.txt:
    echo -------------------------------------------------------------------------
    type "adbrecent_ignore.txt"
    echo -------------------------------------------------------------------------
    )

    :done
    echo.
    echo Exiting adbrecent. Goodbye!
    pause
    :: -------------------------------------------------------------------------
    :: end of adbrecent.bat
    :: ------------------------------------------------------------------------- --
    Helping others & learning from them is what this Usenet ng is all about.
    --- Synchronet 3.22a-Linux NewsLink 1.2