When to use Scripts over Macros

Help with writing and running scripts

When to use Scripts over Macros

Postby jhtexas » Mon Oct 01, 2007 12:58 pm

Is there a general rule of thumb on when to use a script instead of a macro? Can scripts do everything a macro can do and more?
I know this question might be hard to give a definitive answer to but if someone could elaborate on the subject I'd appreciate it.

JH
User avatar
jhtexas
Basic User
Basic User
 
Posts: 10
Joined: Tue Aug 01, 2006 11:00 pm

Re: When to use Scripts over Macros

Postby Mofi » Mon Oct 01, 2007 2:25 pm

Scripts can much more than macros, but there are some things which cannot be done with scripts.

For example it is not possible with scripts to select a text from actual cursor position or expand an existing selection to end of a found string with a Find Select like it is possible with macros which I often use in my macros.

On the other hand there are script commands and properties not available in the macro environment. See Scripting commands for all available UltraEdit scripting functions and properties and Edit Macro command for all available UltraEdit macro commands and their parameters.

An advantage of macros is that they can be quickly recorded and re-run to redo some commands on the current file. I use that very often. Scripts must be always programmed, they cannot be recorded. That requires programming skills and more time when just do something with the actual file and then the script is not needed anymore.

Scripts have the big advantages of support for variables, easy string manipulations in RAM and there is the possibility to work with the output window. Nesting of loops is also possible in scripts, but not in macros.

In scripts you can also easily add comments which is not possible for macros (except with a workaround). The source of a script can be also easily viewed and formatted with indentations and directly edited in the document window. That's not possible for macros (except with a workaround). The error messages are often better for scripts than for macros.

Scripts are really well when they are designed for a job which must be done daily, weekly or monthly especially when reports should be also created by the scripts. Creating reports with macros is not so easy, mainly because it is not possible to simply copy a fixed text into a clipboard without the usage of an edit window and because there are no variables (counters).

Scripts are also better when working on multiple documents at the same time because data can be modified in a document which currently does not have the focus. In macros the document/window must be always switched when data in another file should be modified or read.

Scripts are now better for complex jobs. But for simple tasks I would still prefer macros over scripts.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4056
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: When to use Scripts over Macros

Postby jhtexas » Fri Oct 05, 2007 1:30 am

Mofi,
I appreciate your in-depth comparison between the macros and scripts. I think you've saved me a lot of time by knowing the differences.

Best Regards,
JH
User avatar
jhtexas
Basic User
Basic User
 
Posts: 10
Joined: Tue Aug 01, 2006 11:00 pm

Re: When to use Scripts over Macros

Postby rstaveley » Tue Jan 26, 2010 5:13 am

Mofi wrote:Scripts can much more than macros, but there are some things which cannot be done with scripts...

This is a great response, which really ought to be in the UltraEdit help file as a FAQ for newbies like me. UltraEdit clearly has a lot of history and there are clever things which were done with macros in the past, which ought to be done with scripts nowadays.

Mofi wrote:there are some things which cannot be done with scripts

More than two years have past since you posted this, Mofi. Is this still true? Do we still have to learn macro programming as well as scripting to get full value from UltraEdit 15.20 (e.g. to select text from the cursor position)?

If so, it would be good to know how to invoke macro functions and pass data to and from scripts so that newbies can use macros for as little as possible (other than recording) and focus their attention on ECMA scripting.
rstaveley
Basic User
Basic User
 
Posts: 13
Joined: Mon Jan 25, 2010 5:32 am

Re: When to use Scripts over Macros

Postby Mofi » Tue Jan 26, 2010 1:13 pm

See replacment for macro command Find Select.

The other macro commands not available in the script environment are:

NextDocument and PreviousDocument
NextWindow and PreviousWindow

The first 2 commands are simply not required in script environment because scripts can access all open documents parallel which is not possible in macros. The other 2 commands are mainly also for switching the active document and are therefore also normally not required within scripts.

It is not possible to run macros from within a script and it is also not possible to run scripts from within macros.

There are some small differences on some commands in special cases, but I think every other macro command is also available in the script environment.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4056
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: When to use Scripts over Macros

Postby rstaveley » Fri Jan 29, 2010 5:05 am

Do you reckon it is a fair assessment to say to future-power-user-newbies that they need not bother learning about macros then, and focus on scripting? i.e. Treat the macro language as deprecated (or something internal for the recorder)
rstaveley
Basic User
Basic User
 
Posts: 13
Joined: Mon Jan 25, 2010 5:32 am

Re: When to use Scripts over Macros

Postby Mofi » Fri Jan 29, 2010 8:50 am

For larger tasks newbies should really focus on scripting. The macro environment is for newbies mainly helpful only for small customizations (like my small macros to insert German umlauts based on file extension), for redoing some steps several times after quickly recording them, and when it is necessary to execute some commands on every file load/save which is not possible with scripts (at the moment).
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4056
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Scripts