Macro or Script to Automate Navigation

Macro or Script to Automate Navigation

671
Advanced UserAdvanced User
671

    Feb 23, 2014#1

    Was not entirely sure which forum this belonged to...

    I wish to customise UE to do the following upon a Keystroke (F4):
    1. Goto next bookmark (F2 in my case); and
    2. MoveLineToTopofView

    I started trying to do this with a macro.
    Then I looked into doing this with a script.

    Are there any views about which approach is best?
    In both cases it was step 2 above where I came unstuck.

    Macro Approach:
    GotoBookMark - This worked
    Could not find a command to MoveLineToTopofView. Nor could I find a command to send the shortcut key Alt-subtract

    Script Approach:
    UltraEdit.activeDocument.gotoBookmark(-1);
    Only way I could think of to execute step 2 was to use the write() command to send Alt-Subtract.
    But how to do that?

    6,604548
    Grand MasterGrand Master
    6,604548

      Feb 24, 2014#2

      The command MoveLineToTopofView is not available as macro or scripting command as you have already detected by yourself. None of the commands just controlling the display of the text are available as macro or scripting commands as macros and scripts are primary for automated modifications of file contents.

      It is also not possible to execute a command not available as macro or scripting command via its assigned hotkey or chord from within an UltraEdit macro or script.

      Therefore I can make only 2 suggestions:
      1. Send a feature request email to IDM support for additional macro/scripting commands.
      2. Use third-party tools like AutoIt for this task. With this tool it is possible to execute with key F4 the UltraEdit commands to goto next bookmark and move the active line to top of the display when the UltraEdit window has the focus.
      Perhaps forum member Nologic can help you with writing the little AutoIt script for this task.
      Best regards from an UC/UE/UES for Windows user from Austria

      671
      Advanced UserAdvanced User
      671

        Feb 24, 2014#3

        Thank you Mofi - the man who never sleeps :wink:
        I use AutoIT. If I end up scripting something I will post it here. It would be quite simple.
        The more challenging/interesting part would be calling the AutoIT script with a keystroke.
        Can this be done from withing UE?
        If not I also use a brilliant utility called Keytext for keyboard shortcuts. But for program specific shortcuts it is a but cludgy.

        After posting I was reading up on Javascript strings.
        For instance the end of line control characters are obviously processed correctly here as this is out of the UE Help files:

        Code: Select all

        UltraEdit.activeDocument.write(num + "\r\n");
        Presumably the processing of \r\n is a Javascript matter not UE per se?
        If so might there then be a Javascript method to send ASCII codes?
        A am experimenting now will report back (unless someone beats me.....)

          Feb 24, 2014#4

          Tried a few random formats as shown but none seems to correspond to any ASCII character....I guess not then


          6,604548
          Grand MasterGrand Master
          6,604548

            Feb 24, 2014#5

            You have a completely wrong expectation on scripting command write.

            This command does not emulate keystrokes on keyboard usually send by Windows as event messages to the application which of course must be in a state on which those events can be handled. This command inserts (in insert mode) or replaces (in overstrike mode) the contents of the passed string into / over the contents of the file directly.

            And while an UltraEdit macro or script is running, the main task of UltraEdit does not handle Windows system events which of course is necessary as every key hit with UltraEdit window in foreground while macro/script execution being active would result in producing unexpected results.

            There is the macro/script command key for "emulating" some keystrokes. But supported are only a few key commands which move the caret in contents of a file as this is often useful in macros and scripts. You cannot use the command key to trigger an event usually resulting in execution of an internal command by the main event loop of UltraEdit.


            It should be possible to call the AutoIt script via a user tool from within UltraEdit. And of course you can assign whatever key you want to this user tool.

            I'm not sure as I'm not using AutoIt, but I think it is possible that a hotkey like F4 can be assigned directly to an AutoIt script so that AutoIt itself executes the script. And I think it is possible to define that AutoIt interprets the key hit of F4 only as command to run the associated script if UltraEdit window has input focus and not the window of any other application so that F4 works for all other applications unchanged.
            Best regards from an UC/UE/UES for Windows user from Austria

            32
            Basic UserBasic User
            32

              Feb 24, 2014#6

              Edit as you see fit. Launch it anyway you see fit...as a user tool or a batch script that launches UE & the script together...or what have you.

              It's designed to run in the background, til a HotKey Combo is intercepted...then it does something...it will automatically exit when UE does, but it can be terminated early with a HotKey Combo as well.

              Keys are currently assigned to:
              Alt+F6
              F5
              Alt+F5

              It's best not to try overriding an applications default bindings...unexpected things can happen.

              Code: Select all

              Opt( 'SendAttachMode' , 1 )
              Opt( 'WinTitleMatchMode' , 2 )
              
              HotKeySet( '!{F6}' , '_ExitProg' )
              HotKeySet( '{F5}'  , '_BookMarkNext' )
              HotKeySet( '!{F5}' , '_BookMarkPrev' )
              
              While ProcessExists( 'Uedit32.exe' )
              	Sleep( 100 )
              WEnd
              
              Func _ExitProg()
              	Exit
              EndFunc
              
              Func _BookMarkNext()
              	WinActivate( ' - UltraEdit' )
              	Send( '{F2}{ALTDOWN}{NUMPADSUB}{ALTUP}' )
              EndFunc
              
              Func _BookMarkPrev()
              	WinActivate( ' - UltraEdit' )
              	Send( '{ALTDOWN}{F2}{ALTUP}{ALTDOWN}{NUMPADSUB}{ALTUP}' )
              EndFunc

              671
              Advanced UserAdvanced User
              671

                Feb 24, 2014#7

                Thank you Mofi and Nologic.
                I have absolute clarity thank you...

                32
                Basic UserBasic User
                32

                  Feb 25, 2014#8

                  You are certainly welcome...but you don't sound all that pleased.

                  I'm sure you can come up with a cleaner solution...as what I did was rather thrown together.

                  Hehe a redneck coding job. :)

                  671
                  Advanced UserAdvanced User
                  671

                    Feb 25, 2014#9

                    On the contrary I am extremely grateful.
                    It never cease to amaze me how kind and helpful people who never meet each other are on this kind of forum.
                    Once again my thanks - sincerely!
                    When I have time I will look into launching an AutoIT script from UE...