🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.mac.apps
Article #87

Re: Is it possible, with macOS/iOS to do what Windows/Android does?

#87
From: Maria Sophia
Date: Sun, 22 Nov 2026 01:53
1118 lines
53211 bytes
For the record, here is the Windows batch script I wrote yesterday that is 
what we'd like to accomplish with iOS over Wi-Fi/USB to any common desktop.

This only works with Windows, but I'm almost done porting it to Python, 
which means it should work on macOS/Linux also (but I can't test them).

On my 64GB Android, it found about a thousand packages which it listed in 
two panes, one dock, and a few dozen folders, by package name and by label.

In addition, it found 65 headless packages, some of which I simply installed
but forgot to place the launch icon while others are headless (like keyboards).

I'll post the python equivalent separately, which can be run on macOS & Linux
in addition to Windows (although I was only able to test it on Windows).

 :: -------------------------------------------------------------------------
 :: 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, then subsequent panes, from 0 to 1 to 2 and so on to the right.
 ::
 :: Similarly, 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.
 :: The dock and folders in the dock are treated much like the panes are.
 ::
 :: This script not only provides a textual inventory of the name and 
 :: homescreen location of every folder name, package name and display 
 :: name ever added to the homescreen, but it optionally will 'diff' 
 :: against packages which were manually installed by the user but 
 :: which have no current homescreen icon (i.e., "headless" apps).
 ::
 :: 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 traceability. 
 :: Unless the user wipes out the running log, this becomes an automatic
 :: audit of all the physical changes a user has made to the homescreen.
 :: -------------------------------------------------------------------------
 :: Q: Why is saying YES to "Resolve app titles via adb/aapt" very slow?
 :: A: For each of the unplaced packages, the script does:
 ::    a. adb shell dumpsys package <pkg> to look for nonLocalizedLabel=
 ::    b. If that fails: adb shell pm path <pkg> to find the APK location
 ::    c. adb pull <apk> to download the APK to the PC
 ::    d. aapt dump badging <apk> to read the app label from the APK
 ::    Which is up to 4 ADB commands × 65 apps = 260 round-trips.
 ::    Over USB, each round-trip is fast (milliseconds). 
 ::    But, over Wi-Fi, each one has wireless handshake latency, 
 ::    so the total time adds up just waiting on ADB to return results.
 :: -------------------------------------------------------------------------
 :: v6p1 20261121 WIP 
 :: v6p0 20261121 Fixed ADB shell ls wildcard expansion by moving the closing
 ::               quote after %ANDROID_BCK_DIR% so *.novabackup is not treated
 ::               as a literal filename (which had forced a global search)
 :: 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 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
 :: v5p2 20261120 Fixed too many individual syntax problems to count between 
 ::               the last dozen versions, which were Windows CLI issues
 :: v4p5 20261119 Fixed loose apps package_name extraction in :run_query
 ::               when component= has no slash or uses package=
 :: v4p4 20261119 Improved comments regarding filtering of the output data
 :: 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
 :: -------------------------------------------------------------------------
 @echo off
 setlocal enabledelayedexpansion
 cd /d "%~dp0"
 
 :: --- Debug flag 1 = verbose DEBUG traces, 0 = quiet ---
 set "DEBUG=0"
 :: set "DEBUG=1"
 
 :: --- Configurable paths ---
 set "ADB_EXE=C:\app\editor\android\scrcpy\adb.exe"
 set "SQLITE_EXE=C:\app\editor\android\sdk\platform-tools\sqlite3.exe"
 set "WORK_DIR=C:\app\editor\android\scrcpy\nova"
 set "ANDROID_BCK_DIR=/storage/emulated/0/0000/bck/nova_backup"
 set "DEFAULT_CONTAINER=2921"
 
 if "%DEBUG%"=="1" (
     echo [DEBUG] SCRIPT_DIR="%~dp0"
     echo [DEBUG] CD="%CD%"
     echo [DEBUG] ADB_EXE="%ADB_EXE%"
     echo [DEBUG] SQLITE_EXE="%SQLITE_EXE%"
     echo [DEBUG] WORK_DIR="%WORK_DIR%"
 )
 
 :: -------------------------------------------------------------------------
 :: Startup dependency and PATH check for adb exe and sqlite3 exe
 :: -------------------------------------------------------------------------
 echo Checking required tools (adb and sqlite3) ...
 
 set "PATH_ADB="
 for /f "usebackq delims=" %%W in (`where adb 2^>nul`) do (
     if "!PATH_ADB!"=="" set "PATH_ADB=%%W"
 )
 
 set "PATH_SQLITE="
 for /f "usebackq delims=" %%W in (`where sqlite3 2^>nul`) do (
     if "!PATH_SQLITE!"=="" set "PATH_SQLITE=%%W"
 )
 
 if "%DEBUG%"=="1" (
     echo [DEBUG] PATH_ADB="!PATH_ADB!"
     echo [DEBUG] PATH_SQLITE="!PATH_SQLITE!"
 )
 
 :: Prefer configured path if it exists, otherwise fall back to PATH
 if not exist "%ADB_EXE%" (
     if not "!PATH_ADB!"=="" (
         echo [INFO] Configured ADB_EXE not found; using PATH: "!PATH_ADB!"
         set "ADB_EXE=!PATH_ADB!"
     ) else (
         echo [WARN] adb.exe not found at "%ADB_EXE%" and not in PATH.
     )
 ) else if "!PATH_ADB!"=="" (
     echo [INFO] adb.exe found at configured path, though not in PATH.
 )
 
 if not exist "%SQLITE_EXE%" (
     if not "!PATH_SQLITE!"=="" (
         echo [INFO] Configured SQLITE_EXE not found; using PATH: "!PATH_SQLITE!"
         set "SQLITE_EXE=!PATH_SQLITE!"
     ) else (
         echo [ERROR] sqlite3.exe not found at "%SQLITE_EXE%" and not in PATH.
         pause
         exit /b 1
     )
 ) else if "!PATH_SQLITE!"=="" (
     echo [INFO] sqlite3.exe found at configured path, though not in PATH.
 )
 
 if not exist "%WORK_DIR%" mkdir "%WORK_DIR%"
 
 echo Working directory: "%CD%"
 echo Nova work directory: "%WORK_DIR%"
 echo ----------------
 echo.
 echo Select source for Nova Launcher database:
 echo [1] Pull .novabackup from Android via ADB and extract nova.db [Default]
 echo [2] Use an existing nova.db or .novabackup or .zip already on Windows
 echo.
 set "SRC_CHOICE=1"
 set /p "SRC_CHOICE=Enter choice [1 or 2]: "
 if "%DEBUG%"=="1" echo [DEBUG] SRC_CHOICE="!SRC_CHOICE!"
 
 if "%SRC_CHOICE%"=="2" goto :use_local_source
 if "%SRC_CHOICE%"=="1" goto :pull_from_android
 goto :pull_from_android
 
 :: -------------------------------------------------------------------------
 :: Option 1: Pull backup from android via adb
 :: -------------------------------------------------------------------------
 :pull_from_android
 echo.
 echo --- Pull Nova Backup from Android ---
 
 if not exist "%ADB_EXE%" (
     echo [ERROR] adb.exe not found at: "%ADB_EXE%"
     pause
     exit /b 1
 )
 
 set "ADB_TARGET="
 for /f "skip=1 tokens=1" %%g in ('"%ADB_EXE%" devices') do (
     if not "%%g"=="" (
         if "!ADB_TARGET!"=="" set "ADB_TARGET=%%g"
     )
 )
 
 if "%DEBUG%"=="1" echo [DEBUG] ADB_TARGET="!ADB_TARGET!"
 
 if "!ADB_TARGET!"=="" (
     echo [ERROR] No connected ADB devices found.
     pause
     exit /b 1
 )
 
 :: beginning of changes in v5p5
 echo Targeting device: %ADB_TARGET%
 
 set "MAKE_BCK="
 set /p "MAKE_BCK=Open Nova Launcher settings on device to create a new backup first? [y/N]: "
 if /i "!MAKE_BCK!"=="y" (
     echo Launching Nova Launcher settings on %ADB_TARGET% ...
     echo "Tap Backup & restore > Backup > Save to save to your device"
     "%ADB_EXE%" -s %ADB_TARGET% shell am start -n com.teslacoilsw.launcher/com.teslacoilsw.launcher.preferences.SettingsActivity
     echo Create your backup in Nova Launcher on the device, then press ENTER to list backups.
     pause
 )
 
 echo Listing backups in %ANDROID_BCK_DIR% ...
 echo.
 
 "%ADB_EXE%" -s %ADB_TARGET% shell ls -1t "%ANDROID_BCK_DIR%"/*.novabackup 2>nul > "%TEMP%\nova_backups.txt"
 
 if "%DEBUG%"=="1" (
     echo [DEBUG] ls exit errorlevel=!errorlevel!
     echo [DEBUG] Raw %TEMP%\nova_backups.txt contents:
     type "%TEMP%\nova_backups.txt" 2>nul
 )
 
 set "BCK_COUNT=0"
 for /f "usebackq delims=" %%B in ("%TEMP%\nova_backups.txt") do (
     set "LINE=%%B"
     if not "!LINE!"=="" (
         set "LINE=!LINE:^M=!"
         for %%F in ("!LINE!") do set "FNAME=%%~nxF"
         set /a BCK_COUNT+=1
         set "BCK_ITEM_!BCK_COUNT!=!FNAME!"
         set "BCK_PATH_!BCK_COUNT!=!LINE!"
         echo   [!BCK_COUNT!] !FNAME!
         if "%DEBUG%"=="1" (
             echo [DEBUG] BCK_ITEM_!BCK_COUNT!="!FNAME!"
             echo [DEBUG] BCK_PATH_!BCK_COUNT!="!LINE!"
         )
     )
 )
 del "%TEMP%\nova_backups.txt" >nul 2>&1
 
 if %BCK_COUNT% EQU 0 (
     echo [INFO] No .novabackup files found in %ANDROID_BCK_DIR%.
     echo Searching Android storage for *.novabackup files ...
     echo.
 
     "%ADB_EXE%" -s %ADB_TARGET% shell "for d in /storage/emulated/0 /storage/*; do [ -d \"\$d\" ] && [ \"\$d\" != \"/storage/emulated\" ] && find \"\$d\" -maxdepth 5 -name '*.novabackup' 2>/dev/null; done" 2>nul > "%TEMP%\nova_backups_search.txt"
 
     if "%DEBUG%"=="1" (
         echo [DEBUG] Search exit errorlevel=!errorlevel!
         echo [DEBUG] Raw %TEMP%\nova_backups_search.txt contents:
         type "%TEMP%\nova_backups_search.txt" 2>nul
     )
 
     for /f "usebackq delims=" %%S in ("%TEMP%\nova_backups_search.txt") do (
         set "LINE=%%S"
         if not "!LINE!"=="" (
             set "LINE=!LINE:^M=!"
             for %%F in ("!LINE!") do set "FNAME=%%~nxF"
             set /a BCK_COUNT+=1
             set "BCK_ITEM_!BCK_COUNT!=!FNAME!"
             set "BCK_PATH_!BCK_COUNT!=!LINE!"
             echo   [!BCK_COUNT!] !LINE!
             if "%DEBUG%"=="1" (
                 echo [DEBUG] BCK_ITEM_!BCK_COUNT!="!FNAME!"
                 echo [DEBUG] BCK_PATH_!BCK_COUNT!="!LINE!"
             )
         )
     )
     del "%TEMP%\nova_backups_search.txt" >nul 2>&1
 )
 
 if %BCK_COUNT% EQU 0 (
     echo [WARN] No .novabackup files found in %ANDROID_BCK_DIR% or Android storage.
     :manual_bck
     set "BCK_FILE="
     set /p "BCK_FILE=Enter backup filename or full Android path e.g. 2026-11-19_12-57.novabackup: "
     if "!BCK_FILE!"=="" (
         echo [ERROR] No backup filename provided.
         pause
         exit /b 1
     )
     set "BCK_FILE=!BCK_FILE:"=!"
     set "REMOTE_BCK=!BCK_FILE!"
     if not "!REMOTE_BCK:~0,1!"=="/" set "REMOTE_BCK=%ANDROID_BCK_DIR%/!BCK_FILE!"
     for %%F in ("!REMOTE_BCK!") do set "BCK_FILE=%%~nxF"
     goto :pull_selected_backup
 )
 
 echo.
 set "BCK_PICK=1"
 set /p "BCK_PICK=Select backup number [1-%BCK_COUNT%, Default: 1]: "
 if "!BCK_PICK!"=="" set "BCK_PICK=1"
 if "%DEBUG%"=="1" echo [DEBUG] BCK_PICK="!BCK_PICK!"
 
 set "BCK_FILE="
 set "REMOTE_BCK="
 for /l %%N in (1,1,%BCK_COUNT%) do (
     if "!BCK_PICK!"=="%%N" (
         set "BCK_FILE=!BCK_ITEM_%%N!"
         set "REMOTE_BCK=!BCK_PATH_%%N!"
     )
 )
 
 if "!BCK_FILE!"=="" (
     set "CANDIDATE=!BCK_PICK:"=!"
     set "REMOTE_BCK=!CANDIDATE!"
     if not "!REMOTE_BCK:~0,1!"=="/" set "REMOTE_BCK=%ANDROID_BCK_DIR%/!CANDIDATE!"
     for %%F in ("!REMOTE_BCK!") do set "BCK_FILE=%%~nxF"
 )
 if "%DEBUG%"=="1" (
     echo [DEBUG] BCK_FILE="!BCK_FILE!"
     echo [DEBUG] REMOTE_BCK="!REMOTE_BCK!"
 )
 
 :pull_selected_backup
 set "LOCAL_BCK=%WORK_DIR%\%BCK_FILE%"
 set "LOCAL_ZIP=%WORK_DIR%\backup.zip"
 set "EXTRACT_DIR=%WORK_DIR%\backup_extracted"
 
 echo.
 echo Pulling "%REMOTE_BCK%" to "%LOCAL_BCK%" ...
 "%ADB_EXE%" -s %ADB_TARGET% pull "%REMOTE_BCK%" "%LOCAL_BCK%"
 if errorlevel 1 (
     echo [ERROR] Failed to pull backup from Android.
     pause
     exit /b 1
 )
 
 if exist "%LOCAL_ZIP%" del /f /q "%LOCAL_ZIP%"
 ren "%LOCAL_BCK%" "backup.zip"
 if errorlevel 1 (
     echo [ERROR] Failed to rename "%LOCAL_BCK%" to backup.zip.
     pause
     exit /b 1
 )
 
 if exist "%EXTRACT_DIR%" rmdir /s /q "%EXTRACT_DIR%"
 echo Extracting backup.zip to "%EXTRACT_DIR%" ...
 powershell -NoProfile -Command "Expand-Archive -LiteralPath '%LOCAL_ZIP%' -DestinationPath '%EXTRACT_DIR%' -Force"
 if errorlevel 1 (
     echo [ERROR] Failed to extract backup.zip.
     pause
     exit /b 1
 )
 
 set "DB_PATH=%EXTRACT_DIR%\nova.db"
 
 goto :verify_db
 
 :: -------------------------------------------------------------------------
 :: Option 2: Use local nova db or novabackup or zip
 :: -------------------------------------------------------------------------
 :use_local_source
 echo.
 echo --- Local Database Selection ---
 echo Enter the path to nova.db or a .novabackup or .zip file.
 echo Default: "%WORK_DIR%\backup_extracted\nova.db"
 echo.
 
 :ask_local_db
 set "USER_DB="
 set /p "USER_DB=Path to database or backup file [Enter for default]: "
 
 if "!USER_DB!"=="" (
     set "DB_PATH=%WORK_DIR%\backup_extracted\nova.db"
 ) else (
     set "USER_DB=!USER_DB:"=!"
     for %%A in ("!USER_DB!") do set "DB_PATH=%%~fA"
 )
 
 if not exist "%DB_PATH%" (
     echo [ERROR] File not found: "%DB_PATH%"
     set "RETRY="
     set /p "RETRY=Try again? [Y/n]: "
     if /i "!RETRY!"=="n" exit /b 1
     goto :ask_local_db
 )
 
 for %%E in ("%DB_PATH%") do set "EXT=%%~xE"
 if /i "!EXT!"==".novabackup" goto :local_novabackup
 if /i "!EXT!"==".zip" goto :extract_local_archive
 goto :verify_db
 
 :local_novabackup
 echo.
 set "RESTORE_LOCAL="
 set /p "RESTORE_LOCAL=Restore this backup in Nova on the connected device? [y/N]: "
 if /i not "!RESTORE_LOCAL!"=="y" goto :extract_local_archive
 
 if not exist "%ADB_EXE%" (
     echo [ERROR] adb.exe not found at "%ADB_EXE%"; cannot send the backup to the device.
     pause
     exit /b 1
 )
 
 set "RESTORE_TARGET="
 for /f "skip=1 tokens=1" %%g in ('"%ADB_EXE%" devices') do (
     if not "%%g"=="" (
         if "!RESTORE_TARGET!"=="" set "RESTORE_TARGET=%%g"
     )
 )
 
 if "!RESTORE_TARGET!"=="" (
     echo [ERROR] No connected ADB device found; cannot restore the backup.
     pause
     exit /b 1
 )
 
 set "NOVA_BACKUP_DIR=/storage/emulated/0/Android/data/com.teslacoilsw.launcher/files/Backup"
 echo Copying "%DB_PATH%" to Nova's backup folder on !RESTORE_TARGET! ...
 "%ADB_EXE%" -s !RESTORE_TARGET! shell mkdir -p "%NOVA_BACKUP_DIR%"
 if errorlevel 1 (
     echo [ERROR] Could not create Nova's backup folder on the device.
     pause
     exit /b 1
 )
 
 "%ADB_EXE%" -s !RESTORE_TARGET! push "%DB_PATH%" "%NOVA_BACKUP_DIR%/"
 if errorlevel 1 (
     echo [ERROR] Failed to copy the backup to the device.
     pause
     exit /b 1
 )
 
 echo Launching Nova Launcher settings on !RESTORE_TARGET! ...
 "%ADB_EXE%" -s !RESTORE_TARGET! shell am start -n com.teslacoilsw.launcher/com.teslacoilsw.launcher.preferences.SettingsActivity
 echo In Nova, choose Backup & restore and restore the backup you copied.
 goto :extract_local_archive
 
 :extract_local_archive
 set "EXTRACT_DIR=%WORK_DIR%\backup_extracted"
 if exist "%EXTRACT_DIR%" rmdir /s /q "%EXTRACT_DIR%"
 echo Extracting "%DB_PATH%" to "%EXTRACT_DIR%" ...
 powershell -NoProfile -Command "Expand-Archive -LiteralPath '%DB_PATH%' -DestinationPath '%EXTRACT_DIR%' -Force"
 if errorlevel 1 (
     echo [ERROR] Failed to extract archive.
     pause
     exit /b 1
 )
 set "DB_PATH=%EXTRACT_DIR%\nova.db"
 
 :: -------------------------------------------------------------------------
 :: Verify database and list dock, panes, folders and other
 :: -------------------------------------------------------------------------
 :verify_db
 if not exist "%DB_PATH%" (
     echo [ERROR] nova.db not found at: "%DB_PATH%"
     pause
     exit /b 1
 )
 
 echo.
 echo Using database: "%DB_PATH%"
 echo Scanning Nova Launcher dock, panes and folders ...
 echo.
 
 set "TGT_COUNT=0"
 set "LISTED_FOLDER_IDS=,"
 
 :: 1 Dock section first as [1] dock apps plus dock folders if any
 echo dock
 set /a TGT_COUNT+=1
 set "TGT_LABEL_!TGT_COUNT!=dock apps"
 set "TGT_WHERE_!TGT_COUNT!=f.container = -101"
 set "TGT_ORDER_!TGT_COUNT!=f.screen, f.cellY, f.cellX, f.rank, f._id"
 echo   [!TGT_COUNT!] dock apps
 
 "%SQLITE_EXE%" -cmd ".separator |" "%DB_PATH%" "SELECT _id, CASE WHEN title IS NULL OR TRIM(title) = '' THEN '(Untitled Folder)' ELSE title END FROM favorites WHERE itemType = 2 AND container = -101 ORDER BY cellY, cellX, rank, _id;" > "%TEMP%\nova_dock_folders.txt" 2>nul
 for /f "usebackq tokens=1* delims=|" %%A in ("%TEMP%\nova_dock_folders.txt") do (
     set "FID=%%A"
     set "FNAME=%%B"
     set "FNAME=!FNAME:^M=!"
     if not "!FID!"=="" (
         set /a TGT_COUNT+=1
         set "TGT_LABEL_!TGT_COUNT!=dock - !FNAME!"
         set "TGT_WHERE_!TGT_COUNT!=f.container = !FID!"
         set "TGT_ORDER_!TGT_COUNT!=f.rank, f._id"
         set "LISTED_FOLDER_IDS=!LISTED_FOLDER_IDS!!FID!,"
         echo   [!TGT_COUNT!] !FNAME!
     )
 )
 del "%TEMP%\nova_dock_folders.txt" >nul 2>&1
 
 :: 2 Panes 0 to 14 with folders and loose apps via :scan_pane subroutine
 for /l %%P in (0,1,14) do (
     call :scan_pane %%P
 )
 
 :: 3 Other folders not already listed under dock or a pane
 "%SQLITE_EXE%" -cmd ".separator |" "%DB_PATH%" "SELECT _id, CASE WHEN title IS NULL OR TRIM(title) = '' THEN '(Untitled Folder)' ELSE title END FROM favorites WHERE itemType = 2 ORDER BY LOWER(title), _id;" > "%TEMP%\nova_other_folders.txt" 2>nul
 set "OTHER_HAS_FOLDERS=0"
 for /f "usebackq tokens=1* delims=|" %%A in ("%TEMP%\nova_other_folders.txt") do (
     set "FID=%%A"
     set "FNAME=%%B"
     set "FNAME=!FNAME:^M=!"
     if not "!FID!"=="" (
         echo !LISTED_FOLDER_IDS! | findstr /c:",!FID!," >nul
         if errorlevel 1 (
             if "!OTHER_HAS_FOLDERS!"=="0" (
                 echo other
                 set "OTHER_HAS_FOLDERS=1"
             )
             set /a TGT_COUNT+=1
             set "TGT_LABEL_!TGT_COUNT!=other - !FNAME!"
             set "TGT_WHERE_!TGT_COUNT!=f.container = !FID!"
             set "TGT_ORDER_!TGT_COUNT!=f.rank, f._id"
             echo   [!TGT_COUNT!] !FNAME!
         )
     )
 )
 del "%TEMP%\nova_other_folders.txt" >nul 2>&1
 
 echo.
 set "TGT_PICK="
 :: Allow q or 0 to quit cleanly without running a query
 set /p "TGT_PICK=Select number [1-%TGT_COUNT%, q to quit]: "
 if "%DEBUG%"=="1" echo [DEBUG] TGT_PICK="!TGT_PICK!"
 
 if /i "!TGT_PICK!"=="q" goto :check_missing_3p
 if "!TGT_PICK!"=="0" goto :check_missing_3p
 
 set "SELECTED_LABEL="
 set "SQL_WHERE="
 set "SQL_ORDER="
 for /l %%N in (1,1,%TGT_COUNT%) do (
     if "!TGT_PICK!"=="%%N" (
         set "SELECTED_LABEL=!TGT_LABEL_%%N!"
         set "SQL_WHERE=!TGT_WHERE_%%N!"
         set "SQL_ORDER=!TGT_ORDER_%%N!"
     )
 )
 
 if "%DEBUG%"=="1" (
     echo [DEBUG] SELECTED_LABEL="!SELECTED_LABEL!"
     echo [DEBUG] SQL_WHERE="!SQL_WHERE!"
     echo [DEBUG] SQL_ORDER="!SQL_ORDER!"
 )
 
 if "!SQL_WHERE!"=="" (
     echo [ERROR] Invalid selection: "!TGT_PICK!"
     pause
     exit /b 1
 )
 
 :run_query
 if "%DEBUG%"=="1" echo [DEBUG] Entering :run_query
 
 :: Write label character replacer ps1 to %TEMP% so cmd never parses regex characters
 set "PS_SANITIZE=%TEMP%\adbfolder_sanitize.ps1"
 set "SAFE_NAME_FILE=%TEMP%\adbfolder_safename.txt"
 
 > "%PS_SANITIZE%" echo $raw = $env:SELECTED_LABEL
 >> "%PS_SANITIZE%" echo $s = [regex]::Replace($raw, '[\\/:*?"<>|() ]+', '_')
 >> "%PS_SANITIZE%" echo $s = $s.Trim('_')
 >> "%PS_SANITIZE%" echo if ([string]::IsNullOrWhiteSpace($s)) { $s = "nova_target" }
 >> "%PS_SANITIZE%" echo [System.IO.File]::WriteAllText($env:SAFE_NAME_FILE, $s, (New-Object System.Text.UTF8Encoding($false)))
 
 if "%DEBUG%"=="1" (
     echo [DEBUG] Wrote "%PS_SANITIZE%"
     echo [DEBUG] Running character replacer PowerShell script...
 )
 
 powershell -NoProfile -ExecutionPolicy Bypass -File "%PS_SANITIZE%"
 if "%DEBUG%"=="1" echo [DEBUG] Character replacer exit errorlevel=!errorlevel!
 
 set "SAFE_NAME="
 if exist "%SAFE_NAME_FILE%" (
     for /f "usebackq delims=" %%S in ("%SAFE_NAME_FILE%") do set "SAFE_NAME=%%S"
 )
 if "!SAFE_NAME!"=="" set "SAFE_NAME=nova_target"
 
 del "%PS_SANITIZE%" >nul 2>&1
 del "%SAFE_NAME_FILE%" >nul 2>&1
 
 if "%DEBUG%"=="1" echo [DEBUG] SAFE_NAME="!SAFE_NAME!"
 
 set "RAW_OUT=%WORK_DIR%\output.txt"
 set "CLEAN_OUT=%WORK_DIR%\%SAFE_NAME%_apps.txt"
 set "LOG_OUT=%WORK_DIR%\adbfolder_log.txt"
 set "SQL_QUERY_FILE=%TEMP%\adbfolder_query.sql"
 
 if "%DEBUG%"=="1" (
     echo [DEBUG] RAW_OUT="%RAW_OUT%"
     echo [DEBUG] CLEAN_OUT="%CLEAN_OUT%"
     echo [DEBUG] SQL_QUERY_FILE="%SQL_QUERY_FILE%"
 )
 
 echo.
 echo Querying "!SELECTED_LABEL!" ...
 
 > "%SQL_QUERY_FILE%" echo .header on
 >> "%SQL_QUERY_FILE%" echo .mode tabs
 >> "%SQL_QUERY_FILE%" echo SELECT f._id AS item_id,
 >> "%SQL_QUERY_FILE%" echo        f.title AS display_name,
 >> "%SQL_QUERY_FILE%" echo        CASE
 >> "%SQL_QUERY_FILE%" echo          WHEN f.iconPackage IS NOT NULL AND LENGTH(TRIM(f.iconPackage^)^) ^> 0 THEN TRIM(f.iconPackage^)
 >> "%SQL_QUERY_FILE%" echo          WHEN INSTR(f.intent, 'component='^) ^> 0 THEN
 >> "%SQL_QUERY_FILE%" echo            CASE
 >> "%SQL_QUERY_FILE%" echo              WHEN INSTR(SUBSTR(f.intent, INSTR(f.intent, 'component='^) + 10^), '/'^) ^> 0 THEN SUBSTR(SUBSTR(f.intent, INSTR(f.intent, 'component='^) + 10^), 1, INSTR(SUBSTR(f.intent, INSTR(f.intent, 'component='^) + 10^), '/'^) - 1^)
 >> "%SQL_QUERY_FILE%" echo              WHEN INSTR(SUBSTR(f.intent, INSTR(f.intent, 'component='^) + 10^), ';'^) ^> 0 THEN SUBSTR(SUBSTR(f.intent, INSTR(f.intent, 'component='^) + 10^), 1, INSTR(SUBSTR(f.intent, INSTR(f.intent, 'component='^) + 10^), ';'^) - 1^)
 >> "%SQL_QUERY_FILE%" echo              ELSE SUBSTR(f.intent, INSTR(f.intent, 'component='^) + 10^)
 >> "%SQL_QUERY_FILE%" echo            END
 >> "%SQL_QUERY_FILE%" echo          WHEN INSTR(f.intent, 'package='^) ^> 0 THEN
 >> "%SQL_QUERY_FILE%" echo            CASE
 >> "%SQL_QUERY_FILE%" echo              WHEN INSTR(SUBSTR(f.intent, INSTR(f.intent, 'package='^) + 8^), ';'^) ^> 0 THEN SUBSTR(SUBSTR(f.intent, INSTR(f.intent, 'package='^) + 8^), 1, INSTR(SUBSTR(f.intent, INSTR(f.intent, 'package='^) + 8^), ';'^) - 1^)
 >> "%SQL_QUERY_FILE%" echo              ELSE SUBSTR(f.intent, INSTR(f.intent, 'package='^) + 8^)
 >> "%SQL_QUERY_FILE%" echo            END
 >> "%SQL_QUERY_FILE%" echo          ELSE ''
 >> "%SQL_QUERY_FILE%" echo        END AS package_name,
 >> "%SQL_QUERY_FILE%" echo        f.intent
 >> "%SQL_QUERY_FILE%" echo FROM favorites f
 >> "%SQL_QUERY_FILE%" echo WHERE !SQL_WHERE!
 >> "%SQL_QUERY_FILE%" echo ORDER BY !SQL_ORDER!;
 
 "%SQLITE_EXE%" "%DB_PATH%" < "%SQL_QUERY_FILE%" > "%RAW_OUT%"
 
 if "%DEBUG%"=="1" (
     echo [DEBUG] sqlite3 query exit errorlevel=!errorlevel!
     echo [DEBUG] Raw %RAW_OUT% line count:
     find /c /v "" "%RAW_OUT%" 2>nul
 )
 
 del "%SQL_QUERY_FILE%" >nul 2>&1
 
 if errorlevel 1 (
     echo [ERROR] SQLite query failed.
     pause
     exit /b 1
 )
 
 :: Write column formatter ps1 to %TEMP%
 :: Add pane/folder heading, indent spaces and append to log
 set "PS_FORMAT=%TEMP%\adbfolder_format.ps1"
 
 if exist "%PS_FORMAT%" del /f /q "%PS_FORMAT%" >nul 2>&1
 
 >> "%PS_FORMAT%" echo $rawFile = $env:RAW_OUT
 >> "%PS_FORMAT%" echo $cleanFile = $env:CLEAN_OUT
 >> "%PS_FORMAT%" echo $logFile = $env:LOG_OUT
 >> "%PS_FORMAT%" echo $label = $env:SELECTED_LABEL
 >> "%PS_FORMAT%" echo $rows = Import-Csv -LiteralPath $rawFile -Delimiter "`t"
 >> "%PS_FORMAT%" echo $lines = $rows ^| Select-Object package_name, display_name ^| Format-Table -AutoSize ^| Out-String -Width 4096
 >> "%PS_FORMAT%" echo $tableLines = @($lines -split "`r?`n" ^| ForEach-Object { $_.TrimEnd() } ^| Where-Object { $_ -ne '' })
 >> "%PS_FORMAT%" echo $header = "  $label"
 >> "%PS_FORMAT%" echo if ($label -match '^pane\s+(\d+)\s+-\s+(.+)$') { $header = ('  pane {0} folder "{1}"' -f $Matches[1], $Matches[2]) }
 >> "%PS_FORMAT%" echo $body = ($tableLines ^| ForEach-Object { '  ' + $_ }) -join "`r`n"
 >> "%PS_FORMAT%" echo $clean = $header + "`r`n" + $body + "`r`n"
 >> "%PS_FORMAT%" echo $utf8 = New-Object System.Text.UTF8Encoding($false)
 >> "%PS_FORMAT%" echo [System.IO.File]::WriteAllText($cleanFile, $clean, $utf8)
 >> "%PS_FORMAT%" echo $timestamp = Get-Date -Format 'yyyy-MM-dd HH:mm:ss'
 >> "%PS_FORMAT%" echo $entry = "`r`n============================================================`r`nExport: $timestamp`r`n$clean"
 >> "%PS_FORMAT%" echo [System.IO.File]::AppendAllText($logFile, $entry, $utf8)
 
 if "%DEBUG%"=="1" echo [DEBUG] Running formatter PowerShell script "%PS_FORMAT%"...
 powershell -NoProfile -ExecutionPolicy Bypass -File "%PS_FORMAT%"
 if "%DEBUG%"=="1" echo [DEBUG] PowerShell formatter exit errorlevel=!errorlevel!
 
 del "%PS_FORMAT%" >nul 2>&1
 
 if errorlevel 1 (
     echo [ERROR] Failed to format output columns or append running log.
     pause
     exit /b 1
 )
 
 echo.
 echo --- Result (%CLEAN_OUT%) ---
 echo.
 type "%CLEAN_OUT%"
 echo.
 echo Raw tab-delimited output saved to: "%RAW_OUT%"
 echo Formatted app list saved to:      "%CLEAN_OUT%"
 echo Running export log saved to:      "%LOG_OUT%"
 echo.
 
 :: Loop back to menu so user can export another folder or pane
 set "LOOP_MORE="
 set /p "LOOP_MORE=Export another folder or pane? [y/N]: "
 if /i "!LOOP_MORE!"=="y" goto :verify_db
 
 :: -------------------------------------------------------------------------
 :: End-of-run check for third-party packages -3 missing from nova.db
 :: -------------------------------------------------------------------------
 :check_missing_3p
 echo.
 set "CHECK_3P="
 set /p "CHECK_3P=Check user apps -3 with no icon in Nova before quitting? [y/N]: "
 if /i not "!CHECK_3P!"=="y" goto :quit_script
 
 if "%DEBUG%"=="1" (
     echo [DEBUG] Entering :check_missing_3p
     echo [DEBUG] ADB_EXE="%ADB_EXE%"
     echo [DEBUG] SQLITE_EXE="%SQLITE_EXE%"
     echo [DEBUG] DB_PATH="%DB_PATH%"
     echo [DEBUG] ADB_TARGET="%ADB_TARGET%"
 )
 
 if not exist "%ADB_EXE%" (
     echo [INFO] adb.exe not found at "%ADB_EXE%"; skipping device package check.
     goto :quit_script
 )
 
 set "RUN_ADB_TARGET=%ADB_TARGET%"
 if "!RUN_ADB_TARGET!"=="" (
     for /f "skip=1 tokens=1" %%g in ('"%ADB_EXE%" devices') do (
         if not "%%g"=="" (
             if "!RUN_ADB_TARGET!"=="" set "RUN_ADB_TARGET=%%g"
         )
     )
 )
 
 if "%DEBUG%"=="1" echo [DEBUG] RUN_ADB_TARGET="!RUN_ADB_TARGET!"
 
 if "!RUN_ADB_TARGET!"=="" (
     echo [INFO] No connected ADB device found; skipping device package check.
     goto :quit_script
 )
 
 if not exist "%DB_PATH%" (
     echo [INFO] Nova database not available at "%DB_PATH%"; skipping device package check.
     goto :quit_script
 )
 
 set "RESOLVE_LABELS="
 set /p "RESOLVE_LABELS=Resolve app titles via adb/aapt slower over Wi-Fi? [y/N]: "
 set "DO_RESOLVE_LABELS=0"
 if /i "!RESOLVE_LABELS!"=="y" set "DO_RESOLVE_LABELS=1"
 if "%DEBUG%"=="1" echo [DEBUG] DO_RESOLVE_LABELS="!DO_RESOLVE_LABELS!"
 
 set "PM_3P_FILE=%TEMP%\adbfolder_pm3.txt"
 set "NOVA_PKGS_FILE=%TEMP%\adbfolder_nova_pkgs.txt"
 set "UNPLACED_OUT=%WORK_DIR%\unplaced_user_apps.txt"
 set "PS_DIFF_3P=%TEMP%\adbfolder_diff_3p.ps1"
 :: v3p2: Write SQL to a temp .sql file so cmd does not parse SQL operators/quotes
 set "SQL_NOVA_PKGS=%TEMP%\adbfolder_nova_pkgs.sql"
 
 if "%DEBUG%"=="1" (
     echo [DEBUG] PM_3P_FILE="!PM_3P_FILE!"
     echo [DEBUG] NOVA_PKGS_FILE="!NOVA_PKGS_FILE!"
     echo [DEBUG] UNPLACED_OUT="!UNPLACED_OUT!"
     echo [DEBUG] PS_DIFF_3P="!PS_DIFF_3P!"
     echo [DEBUG] SQL_NOVA_PKGS="!SQL_NOVA_PKGS!"
 )
 
 echo Querying third-party packages from device !RUN_ADB_TARGET! ...
 if "%DEBUG%"=="1" echo [DEBUG] Running adb pm list packages -3...
 "%ADB_EXE%" -s !RUN_ADB_TARGET! shell pm list packages -3 2>nul > "!PM_3P_FILE!"
 if "%DEBUG%"=="1" (
     echo [DEBUG] adb pm exit errorlevel=!errorlevel!
     echo [DEBUG] PM_3P_FILE line count:
     find /c /v "" "!PM_3P_FILE!" 2>nul
 )
 
 echo Querying packages referenced anywhere in nova.db ...
 if "%DEBUG%"=="1" echo [DEBUG] Writing and running sqlite3 Nova package query from .sql file...
 :: v3p3: Use LENGTH/TRIM checks instead of != so delayed expansion cannot drop negation
 > "!SQL_NOVA_PKGS!" echo SELECT DISTINCT package_name
 >> "!SQL_NOVA_PKGS!" echo FROM (
 >> "!SQL_NOVA_PKGS!" echo   SELECT CASE
 >> "!SQL_NOVA_PKGS!" echo     WHEN iconPackage IS NOT NULL AND LENGTH(TRIM(iconPackage^)^) ^> 0 THEN TRIM(iconPackage^)
 >> "!SQL_NOVA_PKGS!" echo     WHEN INSTR(intent, 'component='^) ^> 0 THEN
 >> "!SQL_NOVA_PKGS!" echo       CASE
 >> "!SQL_NOVA_PKGS!" echo         WHEN INSTR(SUBSTR(intent, INSTR(intent, 'component='^) + 10^), '/'^) ^> 0 THEN SUBSTR(
 >> "!SQL_NOVA_PKGS!" echo           SUBSTR(intent, INSTR(intent, 'component='^) + 10^),
 >> "!SQL_NOVA_PKGS!" echo           1,
 >> "!SQL_NOVA_PKGS!" echo           INSTR(SUBSTR(intent, INSTR(intent, 'component='^) + 10^), '/'^) - 1
 >> "!SQL_NOVA_PKGS!" echo         ^)
 >> "!SQL_NOVA_PKGS!" echo         ELSE SUBSTR(intent, INSTR(intent, 'component='^) + 10^)
 >> "!SQL_NOVA_PKGS!" echo       END
 >> "!SQL_NOVA_PKGS!" echo     ELSE ''
 >> "!SQL_NOVA_PKGS!" echo   END AS package_name
 >> "!SQL_NOVA_PKGS!" echo   FROM favorites
 >> "!SQL_NOVA_PKGS!" echo )
 >> "!SQL_NOVA_PKGS!" echo WHERE LENGTH(package_name^) ^> 0;
 
 "%SQLITE_EXE%" "%DB_PATH%" < "!SQL_NOVA_PKGS!" > "!NOVA_PKGS_FILE!"
 if "%DEBUG%"=="1" (
     echo [DEBUG] sqlite3 Nova pkgs exit errorlevel=!errorlevel!
     echo [DEBUG] NOVA_PKGS_FILE line count:
     find /c /v "" "!NOVA_PKGS_FILE!" 2>nul
     echo [DEBUG] Writing PS_DIFF_3P script...
 )
 
 :: v3p2: Write PS_DIFF_3P line-by-line instead of an outer parenthesized block
 :: v3p4: Resolve app labels for unplaced packages via adb dumpsys and aapt/aapt2 if available
 :: v3p5: Remove stray caret escaping before closing paren on standalone echo lines
 :: v3p6: Prompt whether to resolve app titles and print periodic progress during lookup
 if exist "!PS_DIFF_3P!" del /f /q "!PS_DIFF_3P!" >nul 2>&1
 >> "!PS_DIFF_3P!" echo $adbExe = $env:ADB_EXE
 >> "!PS_DIFF_3P!" echo $adbTarget = $env:RUN_ADB_TARGET
 >> "!PS_DIFF_3P!" echo $resolveLabels = ($env:DO_RESOLVE_LABELS -eq '1')
 >> "!PS_DIFF_3P!" echo $pm3Lines = Get-Content -LiteralPath $env:PM_3P_FILE -ErrorAction SilentlyContinue
 >> "!PS_DIFF_3P!" echo $installed3 = [System.Collections.Generic.HashSet[string]]::new([System.StringComparer]::OrdinalIgnoreCase)
 >> "!PS_DIFF_3P!" echo foreach ($line in $pm3Lines) {
 >> "!PS_DIFF_3P!" echo     $p = ($line -replace '\r', '').Trim()
 >> "!PS_DIFF_3P!" echo     if ($p.StartsWith('package:')) { $p = $p.Substring(8).Trim() }
 >> "!PS_DIFF_3P!" echo     if (-not [string]::IsNullOrWhiteSpace($p)) { [void]$installed3.Add($p) }
 >> "!PS_DIFF_3P!" echo }
 >> "!PS_DIFF_3P!" echo $novaLines = Get-Content -LiteralPath $env:NOVA_PKGS_FILE -ErrorAction SilentlyContinue
 >> "!PS_DIFF_3P!" echo $inNova = [System.Collections.Generic.HashSet[string]]::new([System.StringComparer]::OrdinalIgnoreCase)
 >> "!PS_DIFF_3P!" echo foreach ($n in $novaLines) {
 >> "!PS_DIFF_3P!" echo     $pkg = ($n -replace '\r', '').Trim()
 >> "!PS_DIFF_3P!" echo     if (-not [string]::IsNullOrWhiteSpace($pkg)) { [void]$inNova.Add($pkg) }
 >> "!PS_DIFF_3P!" echo }
 >> "!PS_DIFF_3P!" echo $missingList = [System.Collections.Generic.List[string]]::new()
 >> "!PS_DIFF_3P!" echo foreach ($pkg in $installed3) {
 >> "!PS_DIFF_3P!" echo     if (-not $inNova.Contains($pkg)) { [void]$missingList.Add($pkg) }
 >> "!PS_DIFF_3P!" echo }
 >> "!PS_DIFF_3P!" echo $missing = @($missingList.ToArray())
 >> "!PS_DIFF_3P!" echo [System.Array]::Sort($missing, [System.StringComparer]::OrdinalIgnoreCase)
 >> "!PS_DIFF_3P!" echo $aaptCmd = if ($resolveLabels) { Get-Command aapt -ErrorAction SilentlyContinue } else { $null }
 >> "!PS_DIFF_3P!" echo $idx = 0
 >> "!PS_DIFF_3P!" echo $results = foreach ($pkg in $missing) {
 >> "!PS_DIFF_3P!" echo     $idx++
 >> "!PS_DIFF_3P!" echo     $label = ''
 >> "!PS_DIFF_3P!" echo     if ($resolveLabels) {
 >> "!PS_DIFF_3P!" echo         if (($idx %% 10) -eq 1 -or $idx -eq $missing.Count) {
 >> "!PS_DIFF_3P!" echo             Write-Host ("Resolving titles: {0}/{1} ({2})..." -f $idx, $missing.Count, $pkg)
 >> "!PS_DIFF_3P!" echo         }
 >> "!PS_DIFF_3P!" echo         $dumpLines = ^& $adbExe -s $adbTarget shell dumpsys package $pkg 2^>$null
 >> "!PS_DIFF_3P!" echo         foreach ($dl in $dumpLines) {
 >> "!PS_DIFF_3P!" echo             if ($dl -match 'nonLocalizedLabel="([^"]+)"') { $label = $Matches[1].Trim() }
 >> "!PS_DIFF_3P!" echo         }
 >> "!PS_DIFF_3P!" echo         if ([string]::IsNullOrWhiteSpace($label) -and $aaptCmd) {
 >> "!PS_DIFF_3P!" echo             $apkPathLine = (^& $adbExe -s $adbTarget shell pm path $pkg 2^>$null ^| Select-Object -First 1)
 >> "!PS_DIFF_3P!" echo             if ($apkPathLine -and $apkPathLine.Trim().StartsWith('package:')) {
 >> "!PS_DIFF_3P!" echo                 $apkRemote = $apkPathLine.Trim().Substring(8).Trim()
 >> "!PS_DIFF_3P!" echo                 $apkLocal = Join-Path $env:TEMP "adbfolder_probe.apk"
 >> "!PS_DIFF_3P!" echo                 ^& $adbExe -s $adbTarget pull $apkRemote $apkLocal ^>$null 2^>^&1
 >> "!PS_DIFF_3P!" echo                 if (Test-Path -LiteralPath $apkLocal) {
 >> "!PS_DIFF_3P!" echo                     $badging = ^& $aaptCmd.Source dump badging $apkLocal 2^>$null
 >> "!PS_DIFF_3P!" echo                     foreach ($bl in $badging) {
 >> "!PS_DIFF_3P!" echo                         if ($bl -match "^application-label:'([^']+)'") { $label = $Matches[1].Trim(); break }
 >> "!PS_DIFF_3P!" echo                     }
 >> "!PS_DIFF_3P!" echo                     Remove-Item -LiteralPath $apkLocal -Force -ErrorAction SilentlyContinue
 >> "!PS_DIFF_3P!" echo                 }
 >> "!PS_DIFF_3P!" echo             }
 >> "!PS_DIFF_3P!" echo         }
 >> "!PS_DIFF_3P!" echo     }
 >> "!PS_DIFF_3P!" echo     [PSCustomObject]@{ package_name = $pkg; app_title = $label }
 >> "!PS_DIFF_3P!" echo }
 >> "!PS_DIFF_3P!" echo $tableText = if (@($results).Count -gt 0) {
 >> "!PS_DIFF_3P!" echo     ((@($results) ^| Format-Table -AutoSize ^| Out-String -Width 4096) -split "`r?`n" ^| ForEach-Object { $_.TrimEnd() } ^| Where-Object { $_ -ne '' }) -join "`r`n" + "`r`n"
 >> "!PS_DIFF_3P!" echo } else { "" }
 >> "!PS_DIFF_3P!" echo [System.IO.File]::WriteAllText($env:UNPLACED_OUT, $tableText, (New-Object System.Text.UTF8Encoding($false)))
 >> "!PS_DIFF_3P!" echo Write-Host ("User packages (-3): {0} | In Nova layout: {1} | No icon in Nova: {2}" -f $installed3.Count, $inNova.Count, $missing.Count)
 >> "!PS_DIFF_3P!" echo if (@($results).Count -gt 0) { Write-Host ""; Write-Output $tableText.TrimEnd() }
 
 if "%DEBUG%"=="1" (
     echo [DEBUG] PS_DIFF_3P write exit errorlevel=!errorlevel!
     echo [DEBUG] Generated PS_DIFF_3P contents:
     type "!PS_DIFF_3P!" 2>nul
     echo [DEBUG] Executing PS_DIFF_3P...
 )
 
 powershell -NoProfile -ExecutionPolicy Bypass -File "!PS_DIFF_3P!"
 if "%DEBUG%"=="1" echo [DEBUG] PS_DIFF_3P execution exit errorlevel=!errorlevel!
 
 echo Saved unplaced user app list to: "!UNPLACED_OUT!"
 echo.
 
 if not "%DEBUG%"=="1" (
     del "!PM_3P_FILE!" >nul 2>&1
     del "!NOVA_PKGS_FILE!" >nul 2>&1
     del "!PS_DIFF_3P!" >nul 2>&1
     del "!SQL_NOVA_PKGS!" >nul 2>&1
 ) else (
     echo [DEBUG] Keeping temp files because DEBUG=1:
     echo [DEBUG]   "!PM_3P_FILE!"
     echo [DEBUG]   "!NOVA_PKGS_FILE!"
     echo [DEBUG]   "!PS_DIFF_3P!"
     echo [DEBUG]   "!SQL_NOVA_PKGS!"
 )
 
 :quit_script
 pause
 exit /b 0
 
 :: -------------------------------------------------------------------------
 :: Subroutine: scan_pane <pane_number>
 :: -------------------------------------------------------------------------
 :scan_pane
 set "SCR=%~1"
 
 "%SQLITE_EXE%" -cmd ".separator |" "%DB_PATH%" "SELECT _id, CASE WHEN title IS NULL OR TRIM(title) = '' THEN '(Untitled Folder)' ELSE title END FROM favorites WHERE itemType = 2 AND container = -100 AND CAST(screen AS INTEGER) = %SCR% ORDER BY cellY, cellX, rank, _id;" > "%TEMP%\nova_pane_folders.txt" 2>nul
 
 set "LOOSE_CNT=0"
 "%SQLITE_EXE%" "%DB_PATH%" "SELECT COUNT(*) FROM favorites WHERE container = -100 AND CAST(screen AS INTEGER) = %SCR% AND itemType <> 2;" > "%TEMP%\nova_pane_loose_cnt.txt" 2>nul
 
 for /f "usebackq delims=" %%C in ("%TEMP%\nova_pane_loose_cnt.txt") do (
     if not "%%C"=="" set "LOOSE_CNT=%%C"
 )
 del "%TEMP%\nova_pane_loose_cnt.txt" >nul 2>&1
 
 set "HAS_PANE_FOLDERS=0"
 for /f "usebackq tokens=1* delims=|" %%A in ("%TEMP%\nova_pane_folders.txt") do (
     set "FID=%%A"
     if not "!FID!"=="" set "HAS_PANE_FOLDERS=1"
 )
 
 set "PRINT_HEADER=0"
 if !HAS_PANE_FOLDERS! GTR 0 set "PRINT_HEADER=1"
 if !LOOSE_CNT! GTR 0 set "PRINT_HEADER=1"
 
 if "!PRINT_HEADER!"=="1" echo pane %SCR%
 
 for /f "usebackq tokens=1* delims=|" %%A in ("%TEMP%\nova_pane_folders.txt") do (
     set "FID=%%A"
     set "FNAME=%%B"
     set "FNAME=!FNAME:^M=!"
     if not "!FID!"=="" (
         set /a TGT_COUNT+=1
         set "TGT_LABEL_!TGT_COUNT!=pane %SCR% - !FNAME!"
         set "TGT_WHERE_!TGT_COUNT!=f.container = !FID!"
         set "TGT_ORDER_!TGT_COUNT!=f.rank, f._id"
         set "LISTED_FOLDER_IDS=!LISTED_FOLDER_IDS!!FID!,"
         echo   [!TGT_COUNT!] !FNAME!
     )
 )
 
 if !LOOSE_CNT! GTR 0 (
     set /a TGT_COUNT+=1
     set "TGT_LABEL_!TGT_COUNT!=pane %SCR% loose apps"
     set "TGT_WHERE_!TGT_COUNT!=f.container = -100 AND CAST(f.screen AS INTEGER) = %SCR% AND f.itemType <> 2"
     set "TGT_ORDER_!TGT_COUNT!=f.cellY, f.cellX, f.rank, f._id"
     echo   [!TGT_COUNT!] pane %SCR% loose apps
 )
 
 del "%TEMP%\nova_pane_folders.txt" >nul 2>&1
 goto :eof
 :: -------------------------------------------------------------------------
 :: end of adbfolder.bat
 :: -------------------------------------------------------------------------
 :: 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.]
 :: -------------------------------------------------------------------------
-- 
We don't just share knowledge here, we make each other's knowledge better.
Technical Details
Message-ID: <11dthvi$2p0v$1@nnrp.usenet.blueworldhosting.com>
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!nnrp.usenet.blueworldhosting.com!.POSTED.public-nat-02.vpngate.v4.open.ad.jp!not-for-mail
References: <11dratg$b4h$1@nnrp.usenet.blueworldhosting.com> <11drgbr$3sbdu$1@dont-email.me> <6b01956a$1$20$882e4bbb@reader.netnews.com> <11dt03c$16nr$1@nnrp.usenet.blueworldhosting.com> <1795297313.13E19854-A17F-4966-A840-5CB7DAB46BE7@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!nnrp.usenet.blueworldhosting.com!.POSTED.public-nat-02.vpngate.v4.open.ad.jp!not-for-mail
From: Maria Sophia <mariasophia@comprehension.com>
Newsgroups: misc.phone.mobile.iphone,comp.sys.mac.apps,comp.sys.mac.advocacy
Subject: Re: Is it possible, with macOS/iOS to do what Windows/Android does?
Date: Sat, 21 Nov 2026 21:53:55 -0400
Organization: BWH Usenet Archive (https://usenet.blueworldhosting.com)
Message-ID: <11dthvi$2p0v$1@nnrp.usenet.blueworldhosting.com>
References: <11dratg$b4h$1@nnrp.usenet.blueworldhosting.com> <11drgbr$3sbdu$1@dont-email.me> <6b01956a$1$20$882e4bbb@reader.netnews.com> <11dt03c$16nr$1@nnrp.usenet.blueworldhosting.com> <1795297313.13E19854-A17F-4966-A840-5CB7DAB46BE7@gmail.com>
Reply-To: pusvul@getTjewytR4so+mqe2.invalid
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 22 Nov 2026 01:53:55 -0000 (UTC)
Injection-Info: nnrp.usenet.blueworldhosting.com; posting-account="l//KxG3Ge2LojWvwJg0Igv8F0ChK8RUC9RtOxMPUo3U"; posting-host="IfCZz72xNNlHXBkfV9B6WJEa9xVhaehMJfhAC6fCwnM";
	logging-data="91167"; mail-complaints-to="usenet@blueworldhosting.com"
User-Agent: Mojibake v24p7
Cancel-Lock: sha1:ys8uOO45w3iuDoNjSvVFI0rDHzo= sha256:S9b9BgHo1yXvOt3Jb+S7hJhtXvg10bGfL5zHr4yZd5c=
	sha1:RjSmLCO+yHKcxNyvl8z/3xRxexE= sha256:WxAC606Bxkviy/tUJfO1JoPy2g1WI48Txbucd6ZMy2I=
Content-Language: en-GB