Negate command line options (-openFoldersAsWorkspace)



  • I have two shortcuts for np++. One includes this command line option, -openFoldersAsWorkspace, which works great. A second shortcut does not have any command line options.

    After using the -openFoldersAsWorkspace option, the view is remembered for future launches of np++. Is there an option to:

    a) not remember this option if used on the command line

    b) have a negate feature to disable an option, such as -!openFoldersAsWorkspace



  • Interesting. I don’t know of a way to tell it to “not remember”, nor of a way to negate the option from the command line, though someone else might know of a way that I don’t.

    If no one can come up with a workaround for you, then you would follow this FAQ to request a feature (either the command-line negation, or the not-remember-option, or both).

    (Sorry I couldn’t be of more help.)



  • @Greg-Teater

    Both of your suggestions a) and b) would require some changes to the code base of Notepad++ (will not happen in the near future, if ever).

    Thus, my suggestion is to create a desktop shortcut to a script file that changes the config file of your Notepad++ installation before running notepad++.exe. The config file is in XML format, the script has to delete the /NotepadPlus/FileBrowser XML node.

    The following is a VBScript solution. Please note: You have to change lines 19 and 20 according to your needs.

    The location of the Notepad++ config file depends on the type of installation you are running, a portable one or created by the Npp installer.

    Installed by installer: %AppData%\Notepad++\config.xml
    Portable: <Npp-Directory>\config.xml

    Save the script for example as NppLauncher.vbs and create a desktop shortcut to it. Then open the properties of the shortcut and change its target to the following command:

    wscript.exe "<Path-To-The-Script-File>" 
    

    The script forwards all received command line arguments to Notepad++.

    Option Explicit
    
    
    '-------------------------------------------------------------------------------
    'Variables declarations
    '-------------------------------------------------------------------------------
    Dim objFSO, objXmlDoc
    Dim strNppPath, strNppExePath, strConfigPath, strCfgFilePath
    Dim strNodePath, colNodes, objNode
    Dim intCnt, strArguments
    
    
    '-------------------------------------------------------------------------------
    'Create base objects
    '-------------------------------------------------------------------------------
    Set objFSO      = CreateObject("Scripting.FileSystemObject")
    Set objXmlDoc   = CreateObject("MSXml2.DOMDocument.6.0")
    
    strNppPath      = "<Path-To-Npp-Installation-Directory>"
    strConfigPath   = "<Path-To-Directory-With-Npp-Config-File>"
    strNppExePath   = objFSO.BuildPath(strNppPath, "notepad++.exe")
    strCfgFilePath  = objFSO.BuildPath(strConfigPath, "config.xml")
    strNodePath     = "/NotepadPlus/FileBrowser"
    
    
    '-------------------------------------------------------------------------------
    'Main script
    '-------------------------------------------------------------------------------
    'Open Npp XML config file
    objXmlDoc.async              = False
    objXmlDoc.validateOnParse    = False
    objXmlDoc.preserveWhiteSpace = True
    
    objXmlDoc.load(strCfgFilePath)
    
    
    'Delete XML node regarding "Folder as Workspace" feature
    Set colNodes = objXmlDoc.selectNodes(strNodePath)
    
    For Each objNode In colNodes
      Call objNode.parentNode.removeChild(objNode)
    Next
    
    
    'Save Npp XML config file
    objXmlDoc.save(strCfgFilePath)
    
    
    'Start Notepad++ with provided command line arguments
    strArguments = ""
    
    For intCnt = 0 To WScript.Arguments.Count - 1
      strArguments = strArguments & " " & Quote(WScript.Arguments(intCnt))
    Next
    
    Call Execute(strNppExePath, strArguments)
    
    
    
    '===============================================================================
    ' Surround a string with double quotes
    '===============================================================================
    
    Function Quote(ByRef strString)
      Quote = """" & strString & """"
    End Function
    
    
    '===============================================================================
    ' Run application with provided arguments
    '===============================================================================
    
    Function Execute(ByRef strApp, ByRef strArgs)
      Dim objWshShell
    
      Set objWshShell = CreateObject("WScript.Shell")
    
      Execute = objWshShell.Run(Quote(strNppExePath) & " " & strArguments, _
                                1, _
                                False)
    End Function
    

Log in to reply