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...
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.
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
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
Or ist is necessary to change from macro to scripting?
Many thanks in advance
Sven
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"
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
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
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
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?
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?
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
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.
- 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;
- the UltraEdit enhancement to convert the captured output from specified encoding/code page to Unicode in case of capturing to output window;
- 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.
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