Page break Text File saving
-
It seems the macro solution had some interesting aspects.
Maybe you want to carry it through and publish the workings?
If it seems to you a pointless effort at this point, because the OP has a solution, then it’s OK, don’t feel obligated. :-) -
@Alan-Kilborn said in Page break Text File saving:
@Terry-R
It seems the macro solution had some interesting aspects.I wouldn’t necessarily say interesting, actually all the steps were fairly simple. However I’ve hit a snag, and it’s a big one.
When I create the multiple “new #” files (step 1), these files ONLY exist within the NPP environment, they aren’t actual files on disk. So when I use the step to save them, the filename is pre-populated with the tab name (good so far), but the macro does not proceed past this point, instead stopping when the Save As dialog is open, it has to be “Save As” due to file not currently on disk, 1st time to save. So my “automatic” process has broken down.
I recall another solution I had where I did a similar thing, appending the filename (as the tab header shows) as text on the last line to each file loaded. But those files already existed on disk, so the save and close functions worked without any user interaction.
I’ve been searching this forum for articles where mention has been made about editing the macro manually and inserting codes corresponding to button presses or commands, where they will work but aren’t record-able through the normal process, @PeterJones this is where you join in, because you seem to have a very good handle on how to find these codes. I installed NppUISpy plugin, but that doesn’t help here.
So either I need to pre-save these “new #” files before commencing the cut and paste operation or be able to have the macro proceed past the Save As dialog box with the default name in situ.
Any ideas anyone?
Terry
-
@Terry-R said in Page break Text File saving:
I wouldn’t necessarily say interesting… However I’ve hit a snag…
Yep, it is a snag I anticipated from the earlier description.
I thought you had found a solution to it, based on your earlier posting describing the algorithm.
THAT is what I thought could be interesting. :-)Macros sometimes just don’t seem to go “far enough”.
Perhaps that’s why I’m a rather avid scripter.I’ve often started something as a macro, then hit the “how to save-as the file” problem.
It might be nice if thesParam
on the SaveAs action could be used somehow to:- specify a hard filename, or perhaps:
- specify a suffix for the active file, to use when saving the new file (example: an active file of
c:\test\test2.txt
becomesc:\test\test2_mysuffix.txt
- if
sParam
is empty, e.g.sParam=""
then current behavior (open SaveAs and put current file info into the setup of the dialog) is maintained - DISCLAIMER: don’t know that I’ve fully thought this all through :-)
-
@Terry-R said in Page break Text File saving:
I’ve been searching this forum for articles where mention has been made about editing the macro manually and inserting codes corresponding to button presses or commands, where they will work but aren’t record-able through the normal process, @PeterJones this is where you join in, because you seem to have a very good handle on how to find these codes. I installed NppUISpy plugin, but that doesn’t help here.
Well, with the Save As (
41008
, from NppUISpy), it is not recordable, but it is playable. Last August, I shared a macro that did a New, then changed the file-type, then ran Save As, then edited and saved again, proving that you can move beyond Save As. Editing it for creating three new files and three save-as (and commenting using on Alan’s2172
trick so that comments don’t get lost):<Macro name="CreateThreeSaveAsEach" Ctrl="no" Alt="no" Shift="no" Key="0"> <Action type="0" message="2172" wParam="0" lParam="0" sParam="COMMENT: 41001 = File|New" /> <Action type="2" message="0" wParam="41001" lParam="0" sParam="" /> <Action type="0" message="2172" wParam="0" lParam="0" sParam="COMMENT: 41008 = Save|As" /> <Action type="2" message="0" wParam="41008" lParam="0" sParam="" /> <Action type="0" message="2172" wParam="0" lParam="0" sParam="COMMENT: 41001 = File|New" /> <Action type="2" message="0" wParam="41001" lParam="0" sParam="" /> <Action type="0" message="2172" wParam="0" lParam="0" sParam="COMMENT: 41008 = Save|As" /> <Action type="2" message="0" wParam="41008" lParam="0" sParam="" /> <Action type="0" message="2172" wParam="0" lParam="0" sParam="COMMENT: 41001 = File|New" /> <Action type="2" message="0" wParam="41001" lParam="0" sParam="" /> <Action type="0" message="2172" wParam="0" lParam="0" sParam="COMMENT: 41008 = Save|As" /> <Action type="2" message="0" wParam="41008" lParam="0" sParam="" /> </Macro>
This creates a file, runs Save As, waits for me to enter the name in the dialog manually, and does the same thing twice more, for a total of three files.
No, I do not know of a way to pass a name to the Save As command – and using the type2 “menu command” style of command, it’s not going to be possible, because menu commands are, by definition, a single-click action; they are not set up to receive arguments directly.
However, I just had an idea. Let me go run some experiments, and I’ll hopefully be back with another post soon, if it pans out.
-
@PeterJones said in Page break Text File saving:
However, I just had an idea. Let me go run some experiments
I was hoping to use the Notepad++ message NPPM_SAVECURRENTFILEAS, which has a string lParam internally… but the type=0/1 macro commands only send messages to the current Scintilla window, not to the parent Notepad++ window; and the type=2 macro commands only send menu command IDs, not generic messages.
So, from a macro, I still don’t know any way to specify the Save As name. As with Alan, I think this task is better suited to a scripting plugin than a macro.
-
@PeterJones said in Page break Text File saving:
So, from a macro, I still don’t know any way to specify the Save As name.
Thanks for the research. In your post there was a glimmer of hope in that I have the filename already populated. That comes from the tab name “new 1” etc. So I changed the 41006 to 41008 to see if it made a difference, nope!
What’s interesting is that when I recorded the macro I used the “Save” function (41006, and this was in the macro). However what comes up is the “Save As” because obviously the file has never been created on disk.
I thought it would be a long shot as your post referred to be unable to supply a filename, but surely every tab content that you try to save should have a “tab name” which should become the “filename” by default. So wouldn’t the filename field in the Save/Save As dialog box be filled with the default?
So it’s a bust then. Oh well it was an interesting exercise anyways although not terribly complicated. I only attempted this due to my previous foray into macro’s saving a filename (as text) in the file content, updating and closing it which DID work. I thought I was onto a winner!
Cheers
Terry -
@Terry-R said in Page break Text File saving:
I only attempted this due to my previous foray into macro’s saving a filename (as text) in the file content, updating and closing it which DID work
Do you still have that macro? Because I don’t see how you could do that, either.
-
This post is deleted! -
@PeterJones said in Page break Text File saving:
Do you still have that macro? Because I don’t see how you could do that, either.
Sorry, misunderstood question, thought you meant this macro, not the old one. Look here for that:
https://community.notepad-plus-plus.org/topic/17035/batch-function-need-to-add-filename-at-the-end-of-each-paragraph/5Terry
PS you even upvoted me on it
-
@Terry-R said in Page break Text File saving:
but surely every tab content that you try to save should have a “tab name” which should become the “filename” by default. So wouldn’t the filename field in the Save/Save As dialog box be filled with the default?
This IS what happens, whether an as-yet-unsaved-to-disk file has a default name (e.g. “new 1”, “new 4”, etc.) or you’ve right-clicked a “new X” tab and Rename…'d it to something else, e.g. “zzzz”:
However, it feels like I am missing some point in the discussion.
¯\_(ツ)_/¯
-
@Alan-Kilborn said in Page break Text File saving:
However, it feels like I am missing some point in the discussion.
@PeterJones question to me has gone past the current theme, however I had previously responded to his statement
“No, I do not know of a way to pass a name to the Save As command”
in that (as you just pointed out) the filename field is already filled. I think the issue is really that the dialog is waiting for an enter key which I did try to manually insert into the macro code, that only made matters worse. I think the macro idea on the current theme is a dead duck.Terry
-
@guy038 Hello sir, Is there any possibilities of saving name from text file instead of File_1?. Thanks.