Open file from command line into existing instance?

General questions about using TextPad

Moderators: AmigoJack, helios, bbadmin, Bob Hansen, MudGuard

Post Reply
IanOfYork
Posts: 93
Joined: Sat Nov 04, 2017 11:54 am
Location: York, England

Open file from command line into existing instance?

Post by IanOfYork »

I use batch scripts to do all sorts of things and many of them generate text files which then get "sent" to Textpad.
For years, I have run Textpad with a single instance, so the batch scripts always open files in the same window.

Recently I switched to using two instances of Textpad so that I could have two workspaces on the screen at once.
The batch scripts now always launch a NEW instance of Textpad.

How do I "send" a text file into an existing instance?
i.e. The opposite of the -M command line flag.
The most recently used instance would be OK.
User avatar
raffriff42
Posts: 1
Joined: Fri Dec 29, 2023 9:18 am
Location: Florida, USA

Re: Open file from command line into existing instance?

Post by raffriff42 »

To do this you need to find the existing TextPad window and send keystrokes to it. AutoHotkey is one tool that does this. As an AHK coder, I found myself with the same problem, so I have written a solution that works for me, and hopefully for you as well. I posted it in the AutoHotkey forum.

Install AutoHotkey Version 1.1.x. Copy the two files (.ahk and .ini) from the CODE windows in the post above, into a directory somewhere. Compile the script. Finally, figure out how you want to use it. Read the code comments, especially the sample .INI file, which I will repost here:

Code: Select all

;; open_in_textpad_workspace.ini
;; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=124410
;;
;; * 'workspace_home' is where your .TWS workspaces are saved;
;;   the value must be "MyDocuments" (the usual place) or a full path
;;
;; * 'textpad_path' is the path to TextPad.exe; it is only required
;;    if the defauly Registry lookup value is incorrect (this is most likely
;;    to happen when you are running multiple TextPad versions)
;;
[general]
workspace_home  = MyDocuments
textpad_path    =

;; The workspace name determines which TextPad instance will open the file;
;; the program looks for a window whose title contains the workspace name;
;; if none is found, a new TextPad instance is launched with the workspace.
;;
;; * A different workspace MAY optionally be specified for each file extension;
;;   any extensions not specified use the '_default' value
;;
;; * The value (to the right of the '=' sign) is a TextPad Workspace filename,
;;   without the .TWS extension. It (and therefore the name chosen for your Workspace)
;;   must not appear in any other window title on your system
;;
;; * The <workspace> command line option overrides the .INI file.
;;
;; * If no workspace is found in the command line or .INI,
;;   workspace is ignored and the file is opened normally
;;
[workspace]
_default        = ~Txp8-Main
ahk             = ~Txp8-DevMain
bbcode          = ~Txp8-Notes
html            = ~Txp8-Notes
md              = ~Txp8-Notes
Post Reply