Page 1 of 1
Open file from command line into existing instance?
Posted: Mon Aug 14, 2023 7:58 am
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.
Re: Open file from command line into existing instance?
Posted: Mon Jan 01, 2024 9:26 pm
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