How do I force gedit to open a specific file each time I boot my computer?

kr flag

This post here served as a guide at my attempt to force the gedit Text Editor to open a specific file each time I startup my computer. Here are the steps I took:

  1. Create a sample directory and sample text file via mkdir ~/sample && touch ~/sample/sample.txt.
  2. Add the gedit Text Editor to my startup applications via the GNOME Tweak Tool.
  3. Modify the gedit startup command via Startup Applications Preferences. Change the startup command from gedit %U to gedit ~/sample/sample.txt. I also eventually tried gedit "~/sample/sample.txt", which didn't work.
  4. Save, Close, Restart

Upon reboot, gedit Text Editor is automatically launched, but the file opened is "Untitled Document 1". Why isn't gedit opening "~/sample/sample.txt" as I commanded it to? As a test I issued the gedit ~/sample/sample.txt command into GNOME Terminal and it did open "sample.txt" in gedit, as you'd expect.

What's wrong with my process described above? Why isn't "sample.txt" loading upon each restart of my computer, instead of "Untitled Document 1".

codlord avatar
ru flag
Have you tried it without the `~` home shortcut? e.g. `gedit /home/whatever/sample/sample.txt`
kr flag
@mikewhatever but theoretically should my process (#1 - #4) work above? Is this possibly a bug in the Startup Applications Preferences program?
hu flag
Just tested it both ways with full path, and it works. Might want to give it a delay of several seconds.
kr flag
@mikewhatever "give it a delay", so should I change the startup command to `sleep 60 && gedit /home/jophuh/sample/sample.txt` in the Startup Applications Preferences program for a one minute delay? Is that what you meant?
hu flag
Yes, but more like `sleep 5`, unless you want to wait a minute.
Asmit avatar
sg flag
I have to open nautilus on startup on a specific directory like say "~/.local/bin" but the path with ~ in it wasn't working. then I changed the command to just .local/bin and it started working
us flag

If you meant open a file when you log in, then you could use the "Startup Applications", choose add a program and on the command field you type gedit /path/to/file. You could also add the startup action via terminal by doing the following:

echo '[Desktop Entry]
Exec=gedit /path/to/file
Comment[en_US]=Opens file using gedit
Comment=Opens file using gedit
' > $HOME/.config/autostart/filegedit.desktop
chmod +x $HOME/.config/autostart/filegedit.desktop

This adds the action you want to do to the list of startup programs. Note: You should not be using "~" to point to your home directory when creating a script/program, instead use /home/username/

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.