The PSA is I intend to create and post a port of a Windows batch script I
wrote yesterday when creating an Android homescreen-archival capability.
Newsgroups: comp.mobile.android,alt.comp.os.windows-10,alt.msdos.batch
Subject: Can we programmatically get package names of icons in a homescreen folder?
Date: Thu, 19 Nov 2026 16:06:21 -0400
Message-ID: <11dn…@nnrp.usenet.blueworldhosting.com>
But, first, the QUESTION is what is the best/easiest/simplest/etc., way you
would suggest I port from a working Windows batch script to Python?
Since it isn't ported yet, below is a description of what the script does.
The cross-platform porting question is:
Q: What is the easiest/safest/most-portable/etc. way to port to Python?
A: ?
====< below is just a description of what the batch file does >=====
:: -------------------------------------------------------------------------
:: adbfolder.bat
:: -------------------------------------------------------------------------
:: Outputs a perfect textual inventory, with debug capability, of an Android
:: homescreen, including location of all panes, folders, packages and titles.
::
:: Intended to assist in debugging, inventory, archival, backup and restore.
:: Runs on Windows over Wi-Fi/USB, but can be ported to other platforms.
::
:: Will pull a backup from android via adb or read an existing nova db or
:: nova backup archive on windows needing only adb and sql dependencies
::
:: List order is top to bottom, left to right, meaning the leftmost pane
:: is 1st, the topleft folder is 1st, then the next folder to the right.
::
:: Likewise, packages and titles inside of folders are listed in top to
:: bottom order, left to right, providing an exact textual description.
::
:: Bare icons, not inside folders, are listed separately as a line item.
::
:: This script not only provides a complete inventory of every package
:: and title of every folder & icon on the homescreen, but it optionally
:: will 'diff' against all packages installed by the user to indicate
:: 'headless' apps which are installed, but which have no homescreen icon.
::
:: Note the display_name is the current icon title for a given app icon,
:: which can be changed by the user, so it's not always the original.
:: However, for apps installed by the user but without homescreen icons,
:: the optional lookup pulls the app's original defined Android app_label.
::
:: Output is appended to a timestamped running-log file for inventory use.
:: -------------------------------------------------------------------------
:: v5p9 20261121 Reformatted folder and pane output with a descriptive
:: heading and two-space indentation, and added a timestamped
:: running log file that accumulates formatted exports
:: v5p8 20261121 Renamed app_title output column to display_name to
:: distinguish the current homescreen icon title from the
:: original Android application label and reformatted output
:: v5p7 20261121 Moved the restore option to the local-file-path section
:: v5p6 20261121 Improved comments and explanations and user prompts
:: v5p5 20261120 Added option to open Nova Launcher settings on the device
:: to create a fresh homescreen backup before listing/pulling
:: v5p4 20261120 Appended a step-by-step flow description at the bottom
:: v5p3 20261120 Fixed too many syntax issues to count between versions
:: Moved per-pane scanning into a :scan_pane subroutine and
:: cleaned up SQL/batch parsing in the pane loop so menu
:: scanning runs without cmd.exe syntax errors
:: v4p5 20261119 Fixed loose apps package_name extraction in :run_query
:: when component= has no slash or uses package=
:: v4p4 20261119 Replaced "filter" / "filtered" in comments with what the
:: code actually does
:: v4p3 20261119 Kept loose apps with all item types except itemType != 2 and
:: removed parentheses from comment lines across the script
:: v4p2 20261119 Removed extra iconPackage/component= check on loose apps
:: so all non-folder items itemType != 2 on a pane are
:: included without dropping rows
:: v4p1 20261119 Restricted loose apps count and query to items that have a
:: non-empty iconPackage or component= in intent while keeping
:: all existing behavior, comments, and formatting intact
:: v4p0 20261119 Gave up on trying to eliminate empty lines from PowerShell
:: in the optional orphan-packages-with-no-launch icon listing
:: so v4p0 is an exact duplicate of v3p6 which has blank lines
:: v3p9 20261119 Moved menu scanning, SQLite querying, table formatting,
:: and unplaced -3 package diffing into a dedicated PowerShell
:: engine script so cmd.exe never hits block/caret/quote errors
:: and fixed looseapps condition to itemType <> 2 and set DEBUG=0
:: v3p8 20261119 Formatted unplaced user app table directly in PS_DIFF_3P
:: instead of Format-Table to remove blank lines between rows
:: v3p7 20261119 Fixed missing package_name in :run_query by replacing !=
:: with LENGTH/TRIM checks and guarding SUBSTR against missing
:: slashes and fixed pane loose apps SQL_WHERE to f.itemType <> 2
:: v3p6 20261119 Added optional prompt before resolving Nova f.title names
:: in check_missing_3p and printed periodic progress while
:: resolving labels so quick checks finish immediately
:: v3p5 20261119 Removed stray caret escaping before closing parentheses on
:: standalone PS_DIFF_3P echo lines so PowerShell parses the
:: generated script cleanly, and kept DEBUG=1 enabled
:: v3p4 20261119 Added app label lookup via adb dumpsys and optional aapt/aapt2
:: for unplaced user apps in check_missing_3p and set DEBUG=0
:: as the default flag
:: v3p3 20261119 Replaced != with LENGTH/TRIM checks in Nova package SQL
:: query so cmd delayed expansion does not strip negation
:: and handled component= values without a slash safely
:: v3p2 20261119 Wrote Nova package SQL query to a temp .sql file to avoid
:: cmd parsing syntax errors and wrote PS_DIFF_3P line-by-line
:: instead of using an outer parenthesized block
:: v3p1 20261119 Insrumented the orphan section as it was throwing errors
:: v3p0 20261119 Fixed command syntax error when generating the PowerShell
:: diff script in check_missing_3p and wrapped the Nova
:: package query in a subquery so package_name matches cleanly
:: v2p9 20261119 Added a final sanity check before quitting to compare
:: the list of packages that have icons on the homescreen
:: against all the user-installed packages on the phone
:: to create an orphan-packages file that have no icons
:: v2p8 20261119 Added quit option at folder selection prompt and loop back
:: prompt at end to export another folder or pane
:: v2p7 20261119 Replaced fragile DISTINCT screen loop with explicit pane
:: index pass 0 to 9 using CAST screen AS INTEGER so panes
:: with folders or loose apps always appear in order
:: v2p6 20261119 Fixed pane screen query so folders on pane 0, pane 1 and
:: pane 2 display properly along with loose pane apps and other
:: v2p5 20261119 Grouped folders by screen number across panes and kept
:: unmatched folders under other at the bottom
:: v2p4 20261119 Added loose apps choice at the end of each pane with
:: non-folder items and kept other catch-all at the bottom
:: v2p3 20261119 Listed folders under dock and each pane with no default
:: and skipped empty sections
:: v2p2 20261119 Added full-layout option outputting dock and pane headers
:: with package_name and app_title lines
:: v2p1 20261119 Replaced backtick for /f calls on DOCK_TOTAL and PANE_TOTAL
:: with temp file redirects so cmd reliably captures counts
:: v2p0 20261119 Removed ampersand and parenthesis inside comment labels
:: as labels are not comments even though they act like them
:: v1p9 20261119 Removed item_type column from output and grouped folders
:: by their homescreen pane eg, "Pane 0 Folder: weather"
:: v1p8 20261119 Dynamically lists dock, eg, container = -101, and lists
:: homescreen panes by screen number, eg, container = -100,
:: and by named folders eg, itemType = 2, from nova db
:: and includes item_type in output
:: v1p7 20261119 Searches android storage for * novabackup files when none
:: are found in ANDROID_BCK_DIR, storing full remote paths so
:: backups in any folder can be pulled cleanly
:: v1p6 20261119 Set DEBUG=0 by default for clean normal output while keeping
:: the toggle available for troubleshooting
:: v1p5 20261119 Reversed output columns to package_name first, app_title
:: second and added startup dependency check for adb and
:: sqlite3 dependency checking configured paths and PATH
:: v1p4 20261119 Moved powershell commands into %TEMP%\* ps1 scripts run via
:: "-File" instead of backticks so cmd never parses "<" or ">"
:: v1p3 20261119 Added DEBUG=1 instrumentation
:: v1p2 20261119 Replaced cmd FOR sanitizer with powershell
:: v1p1 20261119 Numbered selection menu for novabackup files, lists folders
:: by name with numbered selection instead of raw container IDs
:: v1p0 20261119 Initial version to pull backup or use local nova db, query
:: sql via sqlite3 exe, select columns with powershell
:: -------------------------------------------------------------------------
... snip code ...
:: -------------------------------------------------------------------------
:: Step by step description of what this script does
:: 1. Environment & Configuration Setup
:: A. Command environment
:: a. Disables command echoing and enables delayed expansion
:: b. Sets the working directory to the script's path
:: B. Configuration variables
:: a. Sets default configuration paths for ADB, SQLite
:: and work directories
:: b. Defines the DEBUG toggle flag
:: 2. Dependency Verification
:: A. Executable checks
:: a. Locates adb.exe and checks system PATH or configured fallback path
:: b. Locates sqlite3.exe and exits with an error if missing
:: B. Directory setup
:: a. Creates the local working directory if it does not exist
:: 3. Source Selection Menu
:: A. Choice [1]: Pull from Android via ADB
:: a. Detects connected ADB device target
:: b. Lists .novabackup files in the remote backup directory
:: with fallback search
:: c. Prompts user to select or enter a backup filename/path
:: d. Pulls the selected .novabackup file to the Windows workspace
:: e. Renames the pulled file to backup.zip and extracts it
:: into backup_extracted to retrieve nova.db
:: B. Choice [2]: Use Local Database / Archive
:: a. Prompts user for a custom path to nova.db .novabackup or .zip
:: with a retry loop
:: b. Validates file existence
:: c. Automatically extracts archives if .novabackup or .zip file
:: 4. Database Verification & Target Enumeration
:: A. Database validation
:: a. Verifies that nova.db exists at the target path
:: B. Section 1 [Dock]
:: a. Scans dock apps [container = -101]
:: b. Scans and lists any dock folders
:: C. Section 2 [Panes 0-14]
:: a. Iterates through home screen panes 0 to 14
:: via the scan_pane subroutine
:: b. Queries pane folders [itemType = 2, container = -100]
:: c. Checks for loose non-folder apps [itemType <> 2] on the pane
:: D. Section 3 [Other Folders]
:: a. Searches for orphaned folders not categorized under dock or panes
:: b. Lists and registers valid other folders
:: 5. User Selection & Query Execution [run_query]
:: A. Selection & Sanity
:: a. Prompts user to select a target number or quit [q or 0]
:: b. Sanitizes the selected label using a temporary PowerShell
:: script to generate a safe filename
:: B. Query Generation & Execution
:: a. Writes a dynamic SQLite query script to a temp file
:: [.sql] extracting item ID, app title, package name and raw intent
:: b. Executes the query against nova.db using sqlite3.exe
:: C. Output & Formatting
:: a. Formats output columns [package_name first, display_name second]
:: into an auto-sized table via PowerShell
:: b. Adds a descriptive pane/folder heading and indents the table
:: by two spaces for easier reading and future concatenation
:: c. Saves raw results [output.txt] and formatted results
:: [target_apps.txt] to the work directory
:: d. Appends each formatted export with a timestamp to
:: [adbfolder_log.txt] without overwriting previous exports
:: e. Prompts user to loop back to scan another folder/pane or proceed
:: 6. Optional Unplaced Third-Party Package Check [check_missing_3p]
:: A. Pre-check Validation
:: a. Prompts user whether to check for user-installed packages
:: [-3] missing from the Nova layout
:: b. Verifies ADB device connectivity and database availability
:: c. Optionally prompts user to resolve app labels via adb dumpsys
:: and aapt/aapt2
:: B. Data Collection
:: a. Queries installed third-party packages from device
:: [adb shell pm list packages -3]
:: b. Queries all referenced packages inside nova.db
:: C. Diff Analysis & Cleanup
:: a. Generates and executes a PowerShell diff script to find
:: installed packages with no home screen icon
:: b. Outputs a formatted table of unplaced apps to
:: unplaced_user_apps.txt
:: c. Cleans up temporary script and text files
:: [unless DEBUG=1] and exits cleanly
:: -------------------------------------------------------------------------
:: Not only is there a question of how to port this for more general use,
:: but there's also a question of which common launchers will it work with.
::
:: It may be that the native Android launcher may provide a 'parsable
:: homescreen, so I looked up which might work in addition to Nova Launcher.
::
:: So far, I "think" [tentatively] these will export/import a homescreen.
:: a. Nova [SQL, .novabackup/nova.db restore]
:: b. Lawnchair [.lawnchairbackup/restore]
:: c. Mink [JSON backup/restore]
:: d. Total Launcher [zip? backup/restore]
:: e. Niagra [nlb backup/restore]
:: d. Others? [SQLite, JSON, XML, etc.]
:: ------------------------------------------------------------------------
--
On Usenet, we can pool our knowledge and skills so everyone learns more.