Default File Name Script for gedit

Asked by Dave Hornor

I would like to create a script (right term?) that will allow me to open a gedit text file such that the name of the file will automatically be some form of today's date. I.e. I run the script and gedit fires up with a file name like "2010.05.28 Writing" or some such.

I don't know if properly speaking this a gedit question or a system question. I assume it will involve running edit from the command line.

Thanks for you help!

Dave

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu gedit Edit question
Assignee:
No assignee Edit question
Solved by:
David Mawdsley
Solved:
Last query:
Last reply:
Revision history for this message
Best David Mawdsley (dm-madmod) said :
#1

I think this Bash script should be what you need. Be careful typing if you don't use copy/paste.

1. Copy the script below these directions to a gedit document and save it in your home folder with the name: datefile
2. With Applications | Accessories | Terminal type the command make it executable: chmod u+x datefile
3. To run the script in terminal, type: ./datefile

The script will ask for you to supply a filename, will append it to the day's date and open a blank file in gedit.
Note that if you've already saved a file by that name today it will reopen it with the contents left alone.

Enjoy!

#!/bin/bash
# Append a file name to today's date and open the file in gedit
echo -n "Filename to open in gedit? "
read myText
today=$(date +%b%d%Y)
myFile="${today}$myText"
echo "$myFile"
gedit "$myFile"

Revision history for this message
Dave Hornor (dahornor) said :
#2

David,

Thank you. Very nice. I also found I can associate a bash script file with an icon and put it in my UNR "Favorites." Slicker than a whistle!

Dave H.