<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[PythonScript detect saved&#x2F;unsaved file state at startup]]></title><description><![CDATA[<p dir="auto">I’m having trouble detecting the saved/unsaved state of the filetabs at Notepad++ 8.4.7 startup using a script.  Specifically, I’m being told that I have no unsaved tabs, when I do have some:</p>
<p dir="auto"><img src="/assets/uploads/files/1671455579899-b3aa15b7-2355-4aed-bb25-cb3adecefd3f-image.png" alt="b3aa15b7-2355-4aed-bb25-cb3adecefd3f-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">Here’s the code as text:</p>
<pre><code>if 1:
    import os
    for (pathname, buffer_id, index, view) in notepad.getFiles():
        notepad.activateFile(pathname)
        state = 'unsaved' if editor.getModify() else 'saved'
        print('on startup, activating a {st} "{fn}"'.format(st=state, fn=pathname.rsplit(os.sep, 1)[-1]))
</code></pre>
<p dir="auto">Can anyone that’s inclined to, try and duplicate this?</p>
<p dir="auto">Also, if there are any ideas for successful retrieval of the saved/unsaved state of the tabs at startup, I’d like to hear them.  I have some “wild” ideas, but I lack simple solutions (the kind I like).</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/23908/pythonscript-detect-saved-unsaved-file-state-at-startup</link><generator>RSS for Node</generator><lastBuildDate>Wed, 17 Jun 2026 13:32:27 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/23908.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 19 Dec 2022 13:16:16 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to PythonScript detect saved&#x2F;unsaved file state at startup on Mon, 05 May 2025 15:15:19 GMT]]></title><description><![CDATA[<p dir="auto">After long delay, I made an official Notepad++ issue out of this:</p>
<p dir="auto"><a href="https://github.com/notepad-plus-plus/notepad-plus-plus/issues/16514" rel="nofollow ugc">https://github.com/notepad-plus-plus/notepad-plus-plus/issues/16514</a></p>
<p dir="auto">In the issue, I switched to using NppExec to reproduce, rather than PythonScript, lest it be interpreted as a PS bug and not a N++ bug.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/101462</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/101462</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Mon, 05 May 2025 15:15:19 GMT</pubDate></item><item><title><![CDATA[Reply to PythonScript detect saved&#x2F;unsaved file state at startup on Wed, 28 Dec 2022 11:51:46 GMT]]></title><description><![CDATA[<p dir="auto">Another “wild” idea is to read the N++ “backup” folder for files present there.</p>
<p dir="auto">Example:  If these files are there:</p>
<pre><code class="language-txt">change.log@2022-12-28_064818
new 2@2022-12-26_075922
</code></pre>
<p dir="auto">One can infer that the <code>change.log</code> and <code>new 2</code> filetabs have unsaved changes.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/82838</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/82838</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Wed, 28 Dec 2022 11:51:46 GMT</pubDate></item><item><title><![CDATA[Reply to PythonScript detect saved&#x2F;unsaved file state at startup on Tue, 20 Dec 2022 11:31:10 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: Ekopalypse">@<bdi>Ekopalypse</bdi></a></p>
<p dir="auto">Yes.  Before when I said <em>I have some “wild” ideas…</em>, yours was one of them.  I didn’t want to go <em>that</em> far to solve it.  :-)</p>
<p dir="auto">Maybe I’m attempting to solve something that isn’t really a problem for me, anyway, because I don’t operate with a setup that permits unsaved files when exiting Notepad++ (and thus there is no possibility to have unsaved files when N++ starts up).</p>
<p dir="auto">However, I was working on a script for posting that I was trying to make work in all modes…</p>
]]></description><link>https://community.notepad-plus-plus.org/post/82590</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/82590</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Tue, 20 Dec 2022 11:31:10 GMT</pubDate></item><item><title><![CDATA[Reply to PythonScript detect saved&#x2F;unsaved file state at startup on Tue, 20 Dec 2022 09:19:34 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: Alan-Kilborn">@<bdi>Alan-Kilborn</bdi></a></p>
<p dir="auto">I think the safest way is something like this…</p>
<pre><code class="language-py"># python3
editor.getText() == open(WHAT_EVER_FILE, 'rb').read().decode()
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/82588</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/82588</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Tue, 20 Dec 2022 09:19:34 GMT</pubDate></item><item><title><![CDATA[Reply to PythonScript detect saved&#x2F;unsaved file state at startup on Mon, 19 Dec 2022 17:17:43 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: Alan-Kilborn">@<bdi>Alan-Kilborn</bdi></a> ,</p>
<p dir="auto">Sorry, that wasn’t at startup; that was just “live”.</p>
<p dir="auto">When I did enable periodic-backup and made sure that I had toggled through all the files so it made the 7sec backup for the edited ones, then restarted Notepad++, you are right: it didn’t bring back <code>new 1</code>, and all the files claimed to be saved, even though they are properly shown as edited/unsaved in the tabbar list.</p>
<pre><code>on startup, activating a saved "Peter's Scratchpad.md"
on startup, activating a saved "LICENSE"
on startup, activating a saved "change.log"
on startup, activating a saved "new 2"
on startup, activating a saved "23908-saved-unsaved-list.py"
on startup, activating a saved "startup.py"
</code></pre>
<p dir="auto"><img src="/assets/uploads/files/1671470165719-78b171d2-02c5-4db2-bbfb-135fd91fb428-image.png" alt="78b171d2-02c5-4db2-bbfb-135fd91fb428-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">So at startup, the answer is wrong.  And if I rerun the script manually without making new changes, it still shows them as all being saved.</p>
<p dir="auto">So yes, I concur that getModify() apparently returns whether it’s been changed since the load, rather than whether it’s been changed from the “saved” state.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/82566</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/82566</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Mon, 19 Dec 2022 17:17:43 GMT</pubDate></item><item><title><![CDATA[Reply to PythonScript detect saved&#x2F;unsaved file state at startup on Mon, 19 Dec 2022 16:41:31 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: PeterJones">@<bdi>PeterJones</bdi></a> said in <a href="/post/82564">PythonScript detect saved/unsaved file state at startup</a>:</p>
<blockquote>
<p dir="auto">Maybe it’s a timing issue for you.  Try putting a quarter or half-second sleep</p>
</blockquote>
<p dir="auto">I have never before found this kind of “sleep” to be necessary, in PythonScripting.<br />
But…I tried it, using a full 2 seconds of sleep.<br />
No change for me. :-(</p>
<p dir="auto">Then I thought maybe I should try it with PS 2.0, because, from my earlier output one can see that I was using PS 3.  No change for me from that test either (file still all present “saved”).</p>
<p dir="auto">I’m stumped.  :-(</p>
<blockquote>
<p dir="auto">new1 was unsaved but no changes (no content yet)</p>
</blockquote>
<p dir="auto">This tab would be empty of content, correct?<br />
When I try having such a tab, Notepad++ won’t even “bring it back” after a restart – the tab is eliminated.  I suppose that makes sense: if you’ve created a “scratch” tab, but haven’t put anything in it, why should N++ keep it around?  But…this is not your experience, so…(I don’t know what to make of that).</p>
<p dir="auto">Thanks for doing some experimentation on my behalf, Peter Jones.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/82565</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/82565</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Mon, 19 Dec 2022 16:41:31 GMT</pubDate></item><item><title><![CDATA[Reply to PythonScript detect saved&#x2F;unsaved file state at startup on Mon, 19 Dec 2022 15:57:22 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: Alan-Kilborn">@<bdi>Alan-Kilborn</bdi></a> said in <a href="/post/82559">PythonScript detect saved/unsaved file state at startup</a>:</p>
<blockquote>
<p dir="auto">Can anyone that’s inclined to, try and duplicate this?</p>
</blockquote>
<p dir="auto"><img src="/assets/uploads/files/1671465098414-90f796f3-1695-4c94-90b6-c0e14691e94c-image.png" alt="90f796f3-1695-4c94-90b6-c0e14691e94c-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"><img src="/assets/uploads/files/1671465153770-41d9e92a-8b49-4dc0-9fb6-4f7a4183b5af-image.png" alt="41d9e92a-8b49-4dc0-9fb6-4f7a4183b5af-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">It gives the values I expect: new1 was unsaved but no changes (no content yet), LICENSE was changed and unsaved, new2 was unsaved with changes.  And the script output agreed.</p>
<p dir="auto">Actually, I ran that from the console instead of a script.  Run it again from a saved script:</p>
<p dir="auto"><img src="/assets/uploads/files/1671465339021-a9103b64-df4e-4567-adbf-bbcde64dee82-image.png" alt="a9103b64-df4e-4567-adbf-bbcde64dee82-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">Still works for me.</p>
<p dir="auto">Maybe it’s a timing issue for you.  Try putting a quarter or half-second sleep between the <code>activateFile</code> and the <code>getModify</code> – I know that some of my scripts, I have to give Notepad++ enough time to switch active files and potentially re-lex the document (especially if it’s big)</p>
]]></description><link>https://community.notepad-plus-plus.org/post/82564</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/82564</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Mon, 19 Dec 2022 15:57:22 GMT</pubDate></item></channel></rss>