System environment variables in macros?

System environment variables in macros?

61
Advanced UserAdvanced User
61

    Jun 25, 2005#1

    Is it possible to use an environment variable in a macro? I know that I can do this in a custom tool, but it would be nice to have in a macro...

    6,675585
    Grand MasterGrand Master
    6,675585

      May 27, 2006#2

      You will have thought it already by yourself - no!

      Not even at the Open and SaveAs commands although environment variables can be used in the "File Open" and "Save As" dialogs.
      Best regards from an UC/UE/UES for Windows user from Austria

      2
      NewbieNewbie
      2

        May 24, 2010#3

        Hi, I would like to include the value of windows system variables in an uedit maco (i.e. "username") for documentation of last changes in a file. The macro language has time and date functions, but I don't find hints for including external variables.
        Or ist is necessary to change from macro to scripting?
        Many thanks in advance
        Sven

        6,675585
        Grand MasterGrand Master
        6,675585

          May 24, 2010#4

          UltraEdit macros are not Visual Basic scripts. You can't access Windows environment variables from within an UltraEdit macro. All macro commands are listed in the macro editor or on UltraEdit help page Edit Macro command. That's it, that's all you have.

          There is only one command which gives you the possibility to access something outside UltraEdit, the command RunTool to call one of the 25 user or 25 project tools by name. But that user tool must be configured first from the Advanced menu.

          See How to run ANY console or Windows application from within an UE script/macro? for a general solution to call the command echo %username% from within a macro.

          Or you configure a user tool just for getting the user name as follows:

          On tab Command:

          Menu Item Name: Get User Name (for example)
          Command Line: echo %username%
          Working Directory: (let it empty)
          Toolbar bitmap/icon: (let it empty or browse to a BMP or ICO file)

          On tab Options:

          Program Type: Dos Program
          Save Active File: unchecked
          Save all files first: unchecked

          On tab Output:

          Command Output: Output to List Box
          Show DOS Box: unchecked
          Capture Output: checked
          Replace selected text with: Captured Output

          With that user tool the macro could position the cursor in the active file where the user name should be inserted and then use the command

          RunTool "Get User Name"
          Best regards from an UC/UE/UES for Windows user from Austria

          2
          NewbieNewbie
          2

            May 24, 2010#5

            Hi Mofi,

            many thanks for your solution. Just great! And I will study the link you gave for a good bit of learning more of that.

            Thank you very much
            Sven

            7
            NewbieNewbie
            7

              Oct 27, 2015#6

              Great Post.
              I'm having an issue though. Every time I run the tool GetUserName, I get some Japanese characters (instead of the username). When I run a DOS command (F9) I do get the username English characters. Any ideas as to what setting might be off?

              6,675585
              Grand MasterGrand Master
              6,675585

                Oct 27, 2015#7

                I was wondering already that in all the years UltraEdit has already the feature to capture output of a user tool, nobody has ever detected this issue and requested
                1. a user/project tool option respectively an option in DOS Command dialog to define the encoding/code page used by the called user/project tool respectively the executed console command;
                2. the UltraEdit enhancement to convert the captured output from specified encoding/code page to Unicode in case of capturing to output window;
                3. the UltraEdit enhancement to convert the captured output from specified encoding/code page to encoding/code page of the file in case of capturing to active file replacing current selection or to a new file.
                At least an automatic detection of code page used by default by command processor according to the Windows language settings with an automatic conversion to Unicode (output window) or encoding/code page of target file would be really good for all non ASCII characters in captured output, Unicode encoded target file (multi-byte encoded) and ASCII/ANSI target file (single byte encoded) not using the right OEM code page.

                It looks like most console applications output only text with ASCII characters and most users capture output to output window and not to a Unicode encoded file.

                rtorres, you see "Japanese" characters because UltraEdit writes the bytes of the captured OEM output over the bytes of the selected UTF-16 encoded characters without conversion from OEM (most likely OEM 437 or OEM 850) to Unicode.

                The workaround for the missing conversion feature of captured output is to use the Windows clipboard for the conversion.

                To get an environment variable via Windows clipboard written directly into active file:

                On tab Command:

                Menu item name: Get User Name (for example)
                Command line: echo %username% | clip.exe
                Working directory: (let it empty)
                Toolbar bitmap/icon: (let it empty or browse to a suitable BMP, GIF, ICO, JPG, or PNG file)

                On tab Options:

                Program type: DOS program
                Save active file: unchecked
                Save all files first: unchecked

                On tab Output:

                Command output: Output to list box
                Show DOS box: unchecked
                Capture output: checked
                Replace selected text with: Clipboard

                But the value of the environment variable can be also directly written to the file by the macro or script itself because it is possible to use in an UltraEdit macro the command Paste and in an UltraEdit script the command UltraEdit.activeDocument.paste() or access clipboard content directly via property UltraEdit.clipboardContent. When using output piped to Windows clipboard directly within macro or script, the user tool should be configured as follows:

                On tab Command:

                Menu item name: Get User Name (for example)
                Command line: echo %username% | clip.exe
                Working directory: (let it empty)
                Toolbar bitmap/icon: (let it empty or browse to a suitable BMP, GIF, ICO, JPG, or PNG file)

                On tab Options:

                Program type: DOS program
                Save active file: unchecked
                Save all files first: unchecked

                On tab Output:

                Command output: Output to list box
                Show DOS box: unchecked
                Capture output: unchecked
                Replace selected text with: No replace

                Clip.exe is a Windows standard console application since Windows Server 2003. Clip.exe must be installed on Windows XP, best to directory %SystemRoot%\system32, by copying this file from system directory of Windows Server 2003.

                The command line for the user tool can be also echo %username% | %SystemRoot%\system32\clip.exe which avoids searching for clip.exe in directories of environment variable PATH on execution of the user tool by command processor.

                Note: When the macro / script uses also the user clipboards, make sure to have clipboard 0 (Windows clipboard) selected before running the user tool respectively pasting clipboard content respectively accessing clipboard content.
                Best regards from an UC/UE/UES for Windows user from Austria