Modify prefs.js for all Firefox profiles

Discussion in 'Application Software' started by mysteriously, Oct 4, 2016.

  1. mysteriously

    mysteriously MDL Member

    Jun 11, 2012
    188
    67
    10
    #1 mysteriously, Oct 4, 2016
    Last edited: Nov 6, 2017
    Hello,

    I wrote a script which adds new line to modify prefs.js in Firefox profile. It works when there is only one profile. I'm unable to figure out how to do it for all prefs.js in
    Code:
    "%appdata%\Mozilla\Firefox\Profiles\*.default"
    path. I've tried:
    Code:
    ::Write new line to
    REM cd /d "C:\Users\<username>\Desktop\a"
    REM FOR /D /R %%G in ("*.default") DO CALL :ChangePreferences
    REM For /R %%G in ("*.default") do CALL :ChangePreferences
    REM FOR /D /r %%G in ("*.default") DO CALL :ChangePreferences
    
    
    ::cd /d "%appdata%\Mozilla\Firefox\Profiles\*****.default"
    
    
    :ChangePreferences
    copy prefs.js prefs.js.bak > NUL
    echo user_pref("app.update.enabled", false);>> prefs.js
    ::echo.>> prefs.js
    pause
    goto :END
    
    as well as

    Code:
    FORFILES /m pref.js /s /c DO "cmd /c CALL :ChangePreferences"
    
    
    :ChangePreferences
    copy prefs.js prefs.js.bak > NUL
    echo user_pref("app.update.enabled", false);>> prefs.js
    pause
    
    however none of those works.

    Is there anyone who can help me with it, please?
     
  2. Compo

    Compo MDL Member

    Mar 29, 2011
    137
    103
    10
    #2 Compo, Oct 5, 2016
    Last edited by a moderator: Apr 20, 2017
    Here is an idea for you, the profile names and hence paths should all be stored inside the profiles.ini file.
    Code:
    @Echo Off
    SetLocal
    Set "PF=%AppData%\Mozilla\Firefox\"
    If Not Exist "%PF%" GoTo :EndIt
    For /F "Tokens=1* Delims==" %%A In (
    'FindStr/R "^Path=[A-Z]*" "%PF%Profiles.ini"') Do (Set "FP=%%B"
    Call :Sub "%%FP:/=\%%")
    :EndIt
    Echo( Press any key to exit...
    Timeout -1 1>Nul
    Exit/B
    :Sub
    If Exist "%PF%%~1\" (Set "PP=%PF%%~1") Else (Set "PP=%~1")
    If Not Exist "%PP%\prefs.js" Exit/B
    Set i=0
    :Loop
    If Not Exist "%PP%\prefs.js.bk!i!" (
    Copy "%PP%\prefs.js" "%PP%\prefs.js.bk!i!") Else (Set/A i+=1
    GoTo :Loop)
    (Echo=user_pref("app.update.enabled", false^);
    Echo=)>>"%PP%\prefs.js"
    I would strongly suggest that you make sure that FireFox is not running before changing the content of the preferences file of a currently running profile.