Page 1 of 1

Command line switch to execute a macro on startup

Posted: Thu Aug 01, 2024 6:07 am
by Anonymous Coward
Apologies if this has been asked before. I tried searching the forum with "+command +line +macro" but the query was rejected with this error message:
The following words in your search query were ignored because they are too common words: macro command line.
You must specify at least one word to search for. Each word must consist of at least 3 characters and must not contain more than 14 characters excluding wildcards.
I would like to load a file and run a macro from a command prompt. Right now, if I run

Code: Select all

textpad foo.txt c:\Users\bar\AppData\Roaming\Helios\TextPad\9\MACRO1.TPM

then foo.txt is opened in one tab, and macro1.tpm in another. It would be great if the macro executed in the foo.txt tab instead of opening.

Re: Command line switch to execute a macro on startup

Posted: Fri Aug 02, 2024 7:16 am
by AmigoJack
In the future (or on other boards) you may want to make more than one attempt, since commandline and parameter* do find posts (the asterisk finds not only "parameter" but also words starting with that, like "parameters" - likewise searching for command* does find posts, too, but you can use the asterisk only once tho).

This feature was requested almost 21 years ago already: Create a commandline parameter to start a macro (and exit), but didn't got ever implemented. With just filenames as parameters alone TextPad wouldn't know if you want to open or execute that file, hence a prepending parameter/switch must exist. As of 8.4 the help file lists under "Reference Information > Command Line Parameters" the following:
Command Line Parameters
The command line parameters listed below can be used to start TextPad. They are not case sensitive, but must appear before any file names. Surround any parameters containing spaces with quotation marks ("). Because some of the parameters are mutually exclusive, conflicts are resolved by using the last option specified. Any other parameters are silently ignored. The switch character can be '/' or '-' as shown:

Parameter
Description
  • -av
    Arrange windows vertically tiled.
  • -ah
    Arrange windows horizontally tiled.
  • -ac
    Arrange windows cascaded.
  • -am
    Arrange windows maximized.
  • -ca
    Open any specified file name parameters in the ANSI code set.
  • -cd
    Open any specified file name parameters in the DOS code set.
  • -f "folder"
    Overrides the default folder for storing per user configuration files. (Normally FOLDERID_RoamingAppData\Helios\TextPad\<version>.) If the folder pathname is not absolute, it will be relative to the folder containing TextPad.exe.
  • -i
    Start minimized (iconized).
  • -k
    "folder" Overrides the default folder for storing the license key file. (Normally FOLDERID_ProgramData\Helios\TextPad.) If the folder pathname is not absolute, it will be relative to the folder containing TextPad.exe.
  • -l#
    User interface language, where # is: 7=German, 9=English, 10=Spanish, 12=French, 16=Italian, 17=Japanese, 21=Polish, 25=Russian.
  • -m
    Start another instance, regardless of the setting for "Allow multiple instances".
  • -ol
    Set landscape orientation for printing.
  • -op
    Set portrait orientation for printing.
  • -p "file"
    Print the specified file using default printer.
  • -q
    Don’t display startup "splash" message.
  • -r
    Open any files in the command line as read only.
  • -s
    Started by a DDE shell command.
  • -t "title"
    Append "title" to the main window title bar.
  • -u filename
    Open the file, whose name can contain spaces, but does not need to be quoted.
  • @filename
    Open all the files that are listed, one per line, in the specified file. This overrides the option to load the workspace, specified on the General page of the Preferences dialog box.
Notes:
  • Except when using the -p option, multiple filenames and/or wildcards can follow these command parameters, but they must be quoted to allow for filenames containing spaces.
  • An empty, quoted filename (i.e. "") causes a new document to be created.
  • If the filename to be edited (not printed) is followed by "(<line>[,<col>])", with no intervening spaces, the file will be opened with the cursor at that position. If <line> is a hex number (eg. 0x1a22), a hex view of the file will be created, with the cursor at that address.
eg.

Code: Select all

TEXTPAD.EXE -ac "Read me.txt"(51,20)
In this example TextPad will start up and open "Read me.txt" at line 51, column 20 and display it in a cascaded window.

Re: Command line switch to execute a macro on startup

Posted: Fri Aug 02, 2024 10:31 am
by bbadmin
Is there much demand for this?

Re: Command line switch to execute a macro on startup

Posted: Fri Aug 02, 2024 11:26 am
by AmigoJack
I can't see any sense in starting TextPad with a file and auto-executing a macro on without saving the file and closing TextPad again - for me it would imply to also need to more parameters to
  1. save all open files, and
  2. close TextPad entirely.
  3. However, this results in not needing the GUI at all, so another parameter could tell TextPad not show its window to begin with (to be fair, we have at least -i for that already, but it would still show a task button). But if I'm at that point other tools should be more fitting my taste...
However, if doesn't cause much work to implement a new parameter which then executes a given filename as macro then any demand for it should be irrelevant - I'm not sure what the bigger demand for -t "title" was or is either.

Re: Command line switch to execute a macro on startup

Posted: Fri Aug 02, 2024 9:59 pm
by Anonymous Coward
Thank you for suggesting wildcards in search queries on the forum, and for including "parameter*" as a search term in this case. I can't believe I didn't try that. Duh!

As I am sure is true for many longtime TextPad users, I use/abuse the program in ways that were probably never considered when it was first developed. In this instance, I am using it as a poor man's flat file database to filter directory listings of many thousand lines so I can easily generate a list of filenames, and (with a macro) remove the thousands of irrelevant ones. The last thing the macro does is save the file. I never edit this file after it is generated. I just refer to it. Next time I want to use it, I generate it again.

I know I could do the same thing with a sed or awk script, which I would of course have to write from scratch, run, debug, run, debug, etc. With Textpad, I do what I want while recording a fairly simple macro, save it, and I 'm done. If it doesn't work as intended, it's quicker and easier for me to debug a regex in TextPad and edit the macro containing it than to fight my way through sed or awk.

It is no great hardship for me to run the macro manually. But since I generate the directory listing in a batch file which then opens the result in TextPad, I thought it would be nice if the macro ran from the batch file as well.

Re: Command line switch to execute a macro on startup

Posted: Fri Aug 02, 2024 10:14 pm
by AmigoJack
Anonymous Coward wrote: Fri Aug 02, 2024 9:59 pmI generate the directory listing in a batch file
The listing could be fed to findstr which then only lists lines as per regex, or you could just use batch itself to filter out single lines. While this is beyond TextPad I'm interested in an actual case of
  • how one directory listing would look like
  • how the resulting shortened file should look like
  • which actions your macro carries out (I guess it's just search & replace anyway)
I'm pretty sure this can be done without any GUI program and it still shouldn't be more difficult to maintain. In doubt one could even use Perl or PHP to such a rather easy task, since in both languages you're getting results in nearly no time at all.

Re: Command line switch to execute a macro on startup

Posted: Sat Aug 03, 2024 8:40 am
by bbadmin
In the absence of an option to specify a macro on the command line, a way to achieve the same ends with the minimum number of keystrokes is:
  1. Create the macro and append the "FileSave" command to it.
  2. Assign a shortcut to the macro using Configure » Preferences » Keyboard » Macros.
Then, each time you want to edit the file:
  1. Start TextPad with the file name as a command line parameter.
  2. Type the shortcut for the macro.
  3. Close TextPad.