User to user discussion and support for UltraEdit, UEStudio, UltraCompare, and other IDM applications.

Help with writing and playing macros
3 posts Page 1 of 1
Can anyone help?

I'm running uedit64 from PowerShell.
It wont exit the editor. I have to close/exit the editor window manually.

UltraEdit Text/Hex Editor (x64)


Code: Select all
$In = "\\pubtech\users\pubtechops2\My Documents\UltraEdit Files\TEST FILES MOVE N9"

Get-ChildItem -Path $In -recurse -Include *.edi | ? { $_.FullName -inotmatch 'archive' } |
Foreach-Object {
    & uedit64 /fni $_.FullName /M,E "C:\SCRIPTS\Move N9.mac" | out-null

Note: If I add the = to the /M,E on the command line it wont find the macro. I get a "macro load" popup. Saying it cant find the macro.
The path in the popup is correct. If I take out the = the macro runs but it wont exit or close properly.

MACRO: (I'm doing more, but just this simple bit wont close the editor window, which stops my PowerShell from looping to the next file.)

Code: Select all
Key Ctrl+HOME
Find "ST*180"
CloseFile NoSave
CloseFile NoSave
I don't know anything about syntax of PowerShell and therefore can't really help. I'm quite sure you can find a solution for your PowerShell coding issue on Stack Overflow.

However, it looks like you want to search for files in a directory and for each found file you want to

  1. Start UltraEdit.
  2. Open the found file.
  3. Run the macro on the opened file.
  4. Save the file.
  5. Exit UltraEdit.
That is a very inefficient approach.

Better would be doing the file reformatting task without using a PowerShell script at all and starting UltraEdit only once:

  1. Start UltraEdit with just the macro containing just ReplInFiles commands to reformat all files in that directory matching a file name wildcard pattern.

  2. Start UltraEdit with just the macro written for running a FindInFiles with an empty search string to get into a results file the list of file names with full path matching file name pattern *.edi and then the macro opens, reformats, saves and closes each file in the list before finally closing the results file without saving it and exiting resulting in exiting also UltraEdit. See for example Run Macro on all files within folder.

  3. Start UltraEdit with

    Code: Select all
    "%ProgramFiles%\IDM Computer Solutions\UltraEdit\uedit64.exe" /fni "\\pubtech\users\pubtechops2\My Documents\UltraEdit Files\TEST FILES MOVE N9\*.edi" /M,E="C:\SCRIPTS\Move N9.mac"

    which should result in opening all *.edi files by UltraEdit found in the directory and the macro is written to run once on each opened file.
Best regards from Austria
Thank you.
Your technique does sound more efficient.
I'll try that next as that sounds like a good improvement.
Starting UltraEdit once and then looping thorough my files should run faster.

In the short term I did get the way I was trying to do it to work.
Technical support (thanks Josh) helped me solve my original issue of getting UltraEdit to behave when started from PowerShell.
The mix of forward and backward slashes needed to be "quoted" to avoid issues.

To share with anyone else that may look in future, here is the PowerShell that works.

Code: Select all
$In = "\\pubtech\users\pubtechops2\My Documents\UltraEdit Files\TEST FILES MOVE N9"
$Macro = '/m,e="C:\SCRIPTS\IPG_PROD\BND\Move N9.mac" '

# There is an Archive subfolder, we dont want to go into that folder, so it is excluded.

Get-ChildItem -Path $In -recurse -Include *.edi | ? { $_.FullName -inotmatch 'archive' } |
Foreach-Object {
# Build the full argument object. The spaces are important.
# The forward and backward slashes can cause issues so create one argument object
# to use on the command line
    $arg = "/fni "+$_.FullName+" "+$Macro
    &uedit64  $arg | out-null
3 posts Page 1 of 1