views:

570

answers:

5

Hi Geniuses,

Does anyone know where or how to set the default path/directory on saving python scripts prior to running? On a Mac it wants to save them in the top level ~/Documents directory.. Yuck! I would like to specify a real location.

Any ideas?

Alternatively I'd be cool with just not saving the file (if needed a temp file in /tmp is OK)

Thanks

A: 

If you locate the idlelib directory in your Python install, it will have a few files with the .def extension. config-main.def has instructions on where to put the custom config files. However, looking through these I did not find any configurable paths (your install may vary). Looks like you might need to crack open the editor code to alter it.

kwatford
Yeah this was what I ran up against too. I looked through the *.defs expecting to see an obvious save dir variable but nope..
rh0dium
A: 

If you open a module, that sets the default working directory.

Start IDLE.

File -> Open to open your file. And set the current working directory.

S.Lott
A: 

In my case, the default directory is set to the directory from which I launched IDLE. For instance, if I launched IDLE from a directory called 'tmp' in my home directory, the default save path is set to ~/tmp. So start your IDLE like this:

~/tmp $ idle
[...]
Sridhar Ratnakumar
This is true - but there isn't a way to do it from an Application Executable.
rh0dium
A: 

On Windows (Vista at least, which is what I'm looking at here), shortcut icons on the desktop have a "Start in" field where you can set the directory used as the current working directory when the program starts. Changing that works for me. Anything like that on the Mac? (Starting in the desired directory from the command line works, too.)

Anon
+1  A: 

On OS X, if you launch IDLE.app (by double-clicking or using open(1), for example), the default directory is hardwired to ~/Documents. If you want to change the default permanently, you'll need to edit the file idlemain.py within the IDLE.app application bundle; depending on which Python(s) you have installed, it will likely be in one of:

/Applications/MacPython 2.x/IDLE.app/Contents/Resources
/Applications/MacPython 2.x/IDLE.app/Contents/Resources
/Applications/MacPorts/Python 2.x/IDLE.app/Contents/Resources
/Applications/Python 2.x/IDLE.app/Contents/Resources
/Applications/Python 3.x/IDLE.app/Contents/Resources

Edit the line:

os.chdir(os.path.expanduser('~/Documents'))

On the other hand, if you start IDLE from the command line, for example, with:

$ cd /some/directory    
$ /usr/local/bin/idle

IDLE will use that current directory as the default.

Ned Deily