Arduino IDE no perserving state when go into Energy Saving (Mac)

Sometime i work on a arduino script i will leave the mac and do other things, the mac will flip into screensaver and after that he goes into power saving mode and disabled display and other hardware.

When i come back and want to edit my sketch further everything is lost which is not saved. This isn't how mac widnows work.

Now i have to write again the script i was working on.

Did i missed something?

Version: 2.3.6
Date: 2025-04-09T11:22:51.016Z
CLI Version: 1.2.0
MacOS 15.4.1 (24E263)

Hi @janjuno. The Arduino IDE developers are tracking the bug here:

If you have a GitHub account, you can subscribe to that thread to get notifications of any new developments related to this subject:


:red_exclamation_mark: Please only comment on the GitHub issue thread if you have new technical information that will assist with the resolution. General discussion and support requests are always welcome here on the Arduino Forum.


It might be possible to recover your code in a different way. Arduino IDE copies your sketch to a temporary folder during the compilation process. It is possible the full sketch is still stored in that folder. It would be at this location:

/Users/<username>/Library/Caches/arduino/sketches/<some hash>/<sketch name>/<sketch name>.ino.cpp

(where <username> is your macOS username, <some hash> is some characters used to differentiate the folder name, and <sketch name> is the name of the sketch)


:red_exclamation_mark: The Library folder is hidden by default. You can make it visible by pressing the Command+Shift+. keyboard shortcut.


For example:

/Users/per/Library/Caches/arduino/sketches/1002BFDF019398EC7542B39126F8DEEF/MySketch/MySketch.ino.cpp

Note that a .cpp file extension has been appended to the original sketch filename.

You can try doing a search through that folder for the filename of your sketch.


:warning: This storage location is temporary in nature. It might be overwritten by Arduino IDE or deleted by your operating system at any time. So if you are going to try to recover the sketch from this location, you should do it as soon as possible and immediately move it to a safe location once you find it.

You should also be careful to avoid performing actions that could possibly trigger the loss of the data before attempting the recovery:

  • Do not compile or upload your sketch in Arduino IDE.
  • Do not close Arduino IDE.
  • Do not shut down or restart your computer.
  • Do not perform any operations to automatically free up disk space.

If you find the sketch file in the temporary folder, you will notice Arduino IDE made some changes in the code. These changes are minimal so it will be easy to convert the code back to your original sketch. We can help you out with that if you have trouble.

@janjuno That's strange. My Library folder is, and as far as I know, always has been visible. Since I have gone through many OS upgrades I would think if I did remove hidden in the deep past the upgrades may have re hidden it. Or maybe not.
I don't think I have ever turned my Mac off; I just close the lid. I very frequently have new sketches as a result of copying from the forum to look at somebody's problem, and I do not remember ever losing anything.
Recently, as in today and in the last few days, I have 'lost' all my libraries. I just restarted the IDE, and that fixed it, but nothing was actually lost, just no longer in the side panel.
Just FYI, none of this bothers me enough to complain, but thought you should know just in case it helps.

@ptillisch THX For that Info! Lets hope they fix that asap.

@sonofcy it is more related to not saving a sketch and going into sleep mode an coming back, which everything not saved is lost. Has nothing to do with the librarys.

I was explaining MY symptoms, I don't lose sketches, but I do lose libraries, so the Arduino team may be able to use that info to help in the bug hunt. As I said, I have never powered my Mac off I just put it to sleep by closing the lid, and I often (almost daily) have unsaved sketches. That means it may be more than just sleep that causes it. Maybe the sleep system is different on Silicon Macs than on Intel Macs.

It is expected that you will encounter the bug no matter which specific mechanism is used to put the Mac into sleep mode.

Do you have the "auto save" preference enabled @sonofcy? You can check by selecting Arduino IDE > Settings... from the Arduino IDE menus, and then looking to see whether or not the checkbox next to "Auto save" is filled in the "Preferences" dialog.

The changes to the sketch will only be lost on sleep if you have the "auto save" preference disabled. It is likely that a relatively small number of users are affected by the bug due to the fact that the preference is enabled by default and most users likely are satisfied enough by the default configuration that they don't bother to disable it.

My sketches are in the cloud, so I have to disable auto save in order to prevent certain problems.

OK, then if you have the "auto save" feature disabled it is definitely interesting that you aren't experiencing the fault.

So that we can verify your findings, please try this simple experiment

  1. Select File > New Sketch from the Arduino IDE menus.
    A new sketch will open in an Arduino IDE windows
  2. Add the following text to the new sketch:
    Hello, world!
    
  3. Do not save the sketch.
  4. Verify that the "dirty" indicator is shown to the right of the filename in the editor tab.
  5. Click the image icon at the top left corner of the screen.
    The Apple menu will open.
  6. Select "Sleep" from the Apple menu.
  7. Wait for your computer to go into sleep mode.
  8. Wake your computer.

After waking the computer, do you still see the "Hello, world!" text in the Arduino IDE editor?

NO, it did disappear. I guess I have just gotten lucky in the past. OR it's just my work habits, knowing I was going to put my computer aside, I either saved the sketch I was working on or in the case of a test, ended without saving. I am impressed if I always remembered to do that, but without evidence to the contrary, that must be it, OR I lost data/code that was unimportant (VERY likely as I take better care of MY code).
Thanks for the education.