Opening last sketch

I don't want the Arduino IDE to open the last sketch when I run it. Why on Atheists earth would I want to do that? Notepad started doing that. I don't want that to happen. Notepad has a setting to open blank. I want to start the IDE and select what I'm working on every time. How do I do it?

1 Like

Also why is it when I open a new sketch it opens in another window! I don't want that either. I should be able to configure any software any way I want to. This is 2024. Every single option should be available to change everything on any software. How do I make a new sketch open in a tab and not another window?

1 Like

That is easy, just hire somebody to write it for you.

I like it for the most part the way it currently works. I use several machines and the paths are different, this saves me a lot of time hunting. I want it to open each sketch in another window, I may have 10 different programs up at one time especially when working on network stuff such as CAN. I have Linux Mint and generally open them in different windows. When debugging I may have a dozen programs open in one window, I just switch to the program I want to debug hardware. The tricky part is keeping track of the USB ports.

1 Like

Hi @leictreonaic.

The Arduino IDE developers are tracking the request to add such a configuration feature here:

It is actually a fairly common convention used by text editors and IDEs.

There isn't a good way to do it. However, there are a couple of ways you might get the behavior you want by using the current capabilities of Arduino IDE. I'll describe them below in case you are interested:

Cause IDE to Always Open a Specific Sketch

This isn't exactly what you want, but I think it is the closest you can get with a reasonable approach.

When you pass the path of a sketch as an argument to the Arduino IDE invocation, it will open that sketch instead of restoring the previous session as usual.

You would create a dedicated sketch that serves as your "new" sketch that is opened by Arduino IDE on startup. Create a Windows file shortcut, Linux desktop icon, etc. for the Arduino IDE application. Configure the file shortcut to the path of that sketch to the Arduino IDE executable.

Clear List Of Last Sketches

As for an unreasonable/hacky approach, you could create a system that automatically clears the data from the files where Arduino IDE stores the paths of the sketches to restore on open.

There is a detailed technical explanation of how this data is stored and used here:

https://forum.arduino.cc/t/incorrect-default-sketch-opened-when-starting-ide/1127463/10

To summarize, the data is stored in:

  • The recentRoots field of <configuration folder>/recentworkspace.json
  • The workspaces field of <user data folder>/config.json

I was able to accomplish the desired behavior by opening the files in a text editor, manually removing the data from recentworkspace.json#/recentRoots[] and config.json#/workspaces[], then setting the read-only file attribute on those files to stop Arduino IDE from later being able to write new data. From some quick tests, it appears that crude approach does work, but it causes Arduino IDE to produce some error messages that might be annoying or alarming to the user.

  • The recentRoots field of <configuration folder>/recentworkspace.json
  • The workspaces field of <user data folder>/config.json

So a better approach might be to leave the files writable, but set up a system to automatically clear the data before starting Arduino IDE.

If you want to get fancy, you could use a tool like jq to clear the specific fields of these files. But you can also just delete the two files entirely without causing any problem.

"Configuration Folder" Location

Linux

/home/<username>/.arduinoIDE/

(where <username> is your Linux username)


:exclamation: The .arduinoIDE folder may be hidden by default in your file manager and terminal.


macOS

/Users/<username>/.arduinoIDE/

(where <username> is your macOS username)


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


Windows

C:\Users\<username>\.arduinoIDE\

(where <username> is your Windows username)

"User Data folder" location:

Linux

/home/<username>/.config/arduino-ide/

(where <username> is your Linux username)


:exclamation: The .config folder may be hidden by default in your file manager and terminal.


macOS

/Users/<username>/Library/Application Support/arduino-ide/

(where <username> is your macOS username)


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


Windows

C:\Users\<username>\AppData\Roaming\arduino-ide\

(where <username> is your Windows username)


:exclamation: If looking for it with your file manager or command line, note that the AppData folder is hidden by default. On Windows "File Explorer", you can make it visible by opening the "View" menu, then checking the box next to "☐ Hidden items".


1 Like

Since many of the common sketches consist of only a single file, Arduino users are often under the impression that the .ino file is unit of a sketch project. But this is not true. It is the folder that is the sketch project. The folder may contain multiple sketch code files. All the source files present in that folder are compiled to a single program. In addition, all the .ino files of a sketch are concatenated into a single C++ source file before compiling. This concatenation can be confusing even for users who are advanced in C++ programming but fairly new to Arduino.

This is all documented, but Arduino is intended to make the creation of embedded systems accessible even to the type of person who won't read the documentation before jumping in to a project. The Arduino way is to make these complex endeavors as intuitive as possible. Arduino IDE communicates the sketch project file system intuitively by using a separate window for each sketch project and opening all the primary source files as editor tabs, with the tabs are in the order of .ino file concatenation.

So you can now see that the "sketch per window" design is very intentional and important for Arduino's goal of making embedded systems accessible to everyone.

If you aren't satisfied with this free open source software, feel free to use one of the excellent alternatives, or create your own modified version of Arduino IDE that has the features you think are so important.

1 Like

After looking through some searches and posting and then reading the replies, I think the easy solution here is to just open the files that I want from Documents/Arduino project folders. Not start the Arduino IDE like an application then select a file which has been the normal way to do it with any other application since the beginning of computer time. It doesn't even install like a normal application anyway.

1 Like

Excellent solution!

From the context of your posts, I can see you are using Windows. Arduino IDE is distributed in several packages for Windows. It is true that the "Windows ZIP file" package is not an installer. However, the "Windows Win 10 and newer, 64 bits" package uses an NSIS installer which is very commonly used by applications. In addition, the "Windows MSI installer" package uses Windows Installer, which is also very commonly used. So if you are finding that "it doesn't install like a normal application", it is likely simply that you chose the one of the three that is intentionally provided for those who don't want an installer. Since the average user does want an installer, the ZIP package is the last on the list of download options so it is a bit odd you would chose that one.

Being a new user, I was surprised when the program opened with the last sketch. I was sure there must be something in the settings, but unfortunately not.

It's so easy to accidentally write over an existing sketch with a new one. So the first thing I do when launching the IDE is to open a new sketch & close the old one.