Macros not saving
-
I’ve seen several topics on this question, but most seem to be centered around confusion about where shortcuts.xml resides. I’m 99% sure I’m looking in the correct place.
Debug Info: Notepad++ v8.5.7 (64-bit) Build time : Sep 6 2023 - 23:13:49 Path : C:\Program Files\Notepad++\notepad++.exe Command Line : Admin mode : OFF Local Conf mode : OFF Cloud Config : OFF OS Name : Windows 11 Enterprise (64-bit) OS Version : 22H2 OS Build : 22621.2715 Current ANSI codepage : 1252 Plugins : mimeTools (2.9) NppConverter (4.5) NppExport (0.4) XMLTools (3.1.1.13)
(Though the same thing happened when I ran with -noPlugins)
Steps taken:
- Tried recording & saving a macro. Seems to work fine, and it appears in Macro menu. Exit NPP and restart. No longer there
- Tried modifying the name of the existing macro (Trim Trailing Space and Save). Again, modifies OK in menu, but not changed on restart.
- Manually edit (in another app while NPP is closed)
%AppData%\Notepad++\shortcuts.xml
to change the name of the Trim & Save macro. Once I start NPP, the macro is properly renamed. So this indicates to me that there aren’t permission problems with the file, and that I am looking at the correct file. - If I try to edit the shortcuts.xml file in Windows Notepad while NPP is running, it does not allow me to save, giving an error:
The requested operation cannot be performed on a file with a user-mapped section open
. I assume this is because NPP has the file locked. - If I try to edit the file with NPP it gives the error
This file cannot be saved and it may be protected. Do you want to launch NPP in Administrator mode?
I don’t currently have Admin access (work computer), but I’m guessing this is the key to why the macros aren’t being updated.
Thanks!
-
@Robert-Roth
I’d say you certainly tried your level best to identify the issue, good on you. I would have suggested most things you tried, and even supplying the debug info was a good move. It really helps to remove some of the possible reasons.Whenever I edit the shortcuts file in NPP, I do so in a new session, with absolutely no other instances of NPP running. Edit it, save and close NPP before reopening and using NPP as normal.
As for normally saving a macro, if you are running multiple instances of NPP the last instance closed, if it needs to update the shortcuts file, will do so and maybe that has been your issue?
Terry
-
@Robert-Roth said in Macros not saving:
indicates to me that there aren’t permission problems with the file
That normally would, but given your other results, it’s sure behaving like a permissions problem.
the Windows icacls utility will give you some permission information. In my working setup, I get:
C:> icacls %AppData%\Notepad++ C:\Users\username\AppData\Roaming\Notepad++ NT AUTHORITY\SYSTEM:(I)(OI)(CI)(F) BUILTIN\Administrators:(I)(OI)(CI)(F) WorkDomain\username:(I)(OI)(CI)(F) Successfully processed 1 files; Failed processing 0 files C:> icacls %AppData%\Notepad++\shortcuts.xml C:\Users\username\AppData\Roaming\Notepad++\shortcuts.xml NT AUTHORITY\SYSTEM:(I)(F) WorkDomain\Administrators:(I)(F) WorkDomain\username:(I)(F)
The
WorkDomain\username
entries are my user’s permissions.The
(I)(OI)(CI)(F)
on the folder says that it’s inherited, folder/files inherit, folder/subfolder inherit, full permission. The(I)(F)
on the file says that file is inheriting full permissions. I would expect that yours would say something similar. (Feel free to paste the results into your reply, redact any sensitive information (like your usename and what your work calls your domain, which might give away your employer; highlight the paste then click the </> like you did for the Debug Info)I have heard that sometimes installations that were run by Administrator will set up the permissions on the AppData settings very weirdly.
Other than that, you might want to try the
-settingsDir
command line option, which you can use to create a temporary settings directory in some non-standard location where you know you have complete write access. Or download and temporarily use the portable (zip file) version of Notepad++, and make sure that it properly saves changes for you.If you are brave, you could try to exit Notepad++ completely, rename
%AppData%\Notepad++\
to something else (%AppData%\Notepad++.bak\
, for example), then restart Notepad++: it will re-create the critical config files in the default location, and that might fix the problem, if there are permissions issues. (But it’s drastic, and will lose all your settings… at least until you delete the new copy of the directory and then rename the .bak to the original name.) -
@Robert-Roth One test you could try is to go to Settings / Shortcut mapper and to change any shortcut. You can add a new keyboard mapping, change one of the existing ones, or delete/clear one of them.
Now, exit Notepad++ and take a look at the file date/time for
%AppData%\Notepad++\shortcuts.xml
The date/time should be the current time or within the last couple of minutes.If the
shortcuts.xml
file was modified as expected then restart Notepad++ and verify that the keyboard shortcut you modified is in the state you left it in. You can now fix the shortcut and then exit Notepad++ to save that change back to disk.If the
shortcuts.xml
file was not modified according to the date/time stamp then we can dig into permissions.I did a test and discovered that if your shortcuts.xml file is set to read-only that Notepad++ silently won’t update the shortcuts.xml. From a command prompt do:
cd /d "%appdata%\notepad++" attrib shortcuts.xml
If you see a
R
floating to the left of shortcuts.xml then it’s a read-only file. Clear the read-only flag using:attrib -r shortcuts.xml
-
I added an issue report to github about If shortcuts.xml or config.xml are read-only then Notepad++ silently won’t save changes to those files.
We don’t know yet if @Robert-Roth’s underline issue is that the shortcuts.xml file is read only.
-
@mkupper said in Macros not saving:
I did a test and discovered that if your shortcuts.xml file is set to read-only that Notepad++ silently won’t update the shortcuts.xml
Hmm, are there other ways for this file to become read-only other than a user explicitly setting it this way? If not, then I’d say “user knows what he is doing”, and he is really and truly achieving what he expects, i.e. protecting something from change.
-
@Alan-Kilborn said in Macros not saving:
Hmm, are there other ways for this file to become read-only other than a user explicitly setting it this way?
We don’t know if in this case the file is read-only. I was thinking about the behavior the OP reported, and as an experiment made the shortcuts.xml read-only. I learned that Notepad++ silently ignores errors or does not check for errors when saving the shortcuts.xml and config.xml files. That’s what lead to the github report.
My concerns are about 1) Notepad allowed someone to make changes to their settings even though the configuration file(s) were read-only. The user was not alerted that their changes would only be good for the current session and that Notepad++ would revert its configuration. 2) Notepad++ failed to inform the user when there were errors attempting to save the configuration and that it was not saved.
A user could accidentally set a file to read-only. When you have the file properties dialog box up then read-only is one of the tick boxes.
A user could also intentionally set set a file to read-only but ideally should make it clear to Notepad++ that this is intentional. I don’t know if it’s desirable to be able to structure things so that the settings won’t be saved and the user is never notified.
-
I don’t know where a user’s responsibility ends and it is up to the computer to save him from himself. I come from a time when the user was “very responsible”, so…I think I do know. :-)
Setting a file as “read only” via the operating system (as opposed to a program feature) is the user subverting the system, and that’s OK because user supposedly knows what he’s doing when he does this.
With over 2000 open issues, I’d rather see Notepad++ developers do other things with their time, rather than try to “save the user” from the circumstance of a read-only config file, that the user made read-only himself (again this assumes that some outside influence didn’t make it read-only, but it hasn’t been shown that is reasonably possible). But that’s just me.
-
@Terry-R said in Macros not saving:
Whenever I edit the shortcuts file in NPP, I do so in a new session, with absolutely no other instances of NPP running. Edit it, save and close NPP before reopening and using NPP as normal.
As for normally saving a macro, if you are running multiple instances of NPP the last instance closed, if it needs to update the shortcuts file, will do so and maybe that has been your issue?
I (almost) never have a second instance running, and that certainly wasn’t the case when I ran my tests above.
-
@mkupper said in Macros not saving:
One test you could try is to go to Settings / Shortcut mapper and to change any shortcut. You can add a new keyboard mapping, change one of the existing ones, or delete/clear one of them.
Now, exit Notepad++ and take a look at the file date/time for %AppData%\Notepad++\shortcuts.xml The date/time should be the current time or within the last couple of minutes.
Test #2 in my list essentially is the same. I was watching the timestamp, and it didn’t update.
If the shortcuts.xml file was not modified according to the date/time stamp then we can dig into permissions.
I did a test and discovered that if your shortcuts.xml file is set to read-only that Notepad++ silently won’t update the shortcuts.xml.
runningattrib
on the directory shows only the Archive bit is set on all files. This is true whether or not NPP is running. -
@PeterJones said in Macros not saving:
That normally would, but given your other results, it’s sure behaving like a permissions problem.
the Windows
icacls
utility will give you some permission information. In my working setup, I get:I get identical output when I run
icacls
.I’ll give your other 2 options a try tomorrow. It’s time to clock out.
-
@Robert-Roth Try this:
Exit/close Notepad++
and then from from a command prompt run the following commands. Note that you can copy/paste from the forums into a command prompt window by hovering the mouse over the list of commands below. An icon should appear in the upper-right corner. Select that and the full text of the box gets loaded into the copy/paste buffer. Switch to or start a Command Prompt window and right click in the text area to paste.cls & rem This will clear the screen cd /d %appdata%\notepad++ type shortcuts.xml >tmp ren shortcuts.xml shortcuts-bad.xml ren tmp shortcuts.xml dir /a-d
The goal is to create a copy of the shortcuts.xml file but with a brand new set of permissions or other weirdness.
Click on the small command prompt in the upper-left corner of the Command Prompt window and select
Edit / Select All
which will make the screen all white with black text. Right click the mouse once within the command prompt. It will go back to it’s usual colors and also loads the full screen into the copy/paste buffer.Paste the results into the forums in a format like this including the lines with three back ticks (`)
```
(paste here)
``` -
@mkupper Whelp, that fixed it. Once I replaced it with the former
tmp
, it worked just fine, and I’m able to modify macros.Still not quite sure why this was the case, but this definitely is a simpler test/fix than making a copy of the entire directory.
Thanks, everyone, for the assistance.