Re: Re: Re: Re: Finding the Path to/Directory for the current EvaluationNotebook?
- To: mathgroup at smc.vnet.net
- Subject: [mg43595] Re: [mg43581] Re: [mg43516] Re: [mg43458] Re: [mg43423] Finding the Path to/Directory for the current EvaluationNotebook?
- From: John Fultz <jfultz at wolfram.com>
- Date: Tue, 23 Sep 2003 04:01:38 -0400 (EDT)
- Reply-to: jfultz at wolfram.com
- Sender: owner-wri-mathgroup at wolfram.com
Better solution...use EvaluationNotebook[]. SelectedNotebook[] is doing exactly the right thing (*). Common things you might want to do instead of SelectedNotebook[] are... EvaluationNotebook[]...identifies notebook that the evaluation that called EvaluationNotebook[] is coming from. InputNotebook[]...identifies notebook that is currently accepting keystrokes and menu commands (which never includes palettes...and it may not be the same as EvaluationNotebook[] if, for example, the user has changed focus during an evaluation). ButtonNotebook[]...if executed from within a button, identifies the notebook containing that button (which, obviously, could be a palette). These and other similar functions are in the documentation. Sincerely, John Fultz jfultz at wolfram.com User Interface Group Wolfram Research, Inc. (*) Slightly diversionary, but in case somebody's prepared to mention it...SelectedNotebook[] doesn't presently always do the right thing under MacOS X. Under Windows, it returns notebooks or palettes, depending upon what's selected, as signified by the color of the titlebar, but under MacOS X, it returns only palettes if you have any open. The OS makes it tough to do otherwise, but we're investigating for future versions. But all of the other functions I mentioned work perfectly on all platforms. On Sun, 21 Sep 2003 05:42:20 -0400 (EDT), YAT wrote: >Yes, thats true. A palette is a notebook and if it is open and is >selected then it will be the first object returned by Notebooks[]. I can >only think that if any of the solutions provided are excuted before >anything else then the directory will be set to the relevant directory. >Alternatively a check could be added to my initial post that traverses >the palettes directory and finds a string match between Notebooks[][[1]] >and each element returned by FileNames[] in the palettes directory. >Well spotted Murray Eisenberg. >Work-around -- always ensure the relevant notebook is selected. > > >Murray Eisenberg wrote: >>Neither this solution, nor a longer one previously posted by >>Yasvir-Tesiram, works for me (Mathematica 5.0, under Windows XP): In >>both cases the result returned is a directory of a currently-open >>palette, namely, a palette that has is always-on-top. >> >>jmt wrote: >> >>>Try this : >>>SetDirectory[ >>>DirectoryName[ >>>ToFileName["FileName"/.NotebookInformation[SelectedNotebook[]]]]] >>> >>>On Tuesday 16 September 2003 10:36, AES/newspost wrote: >>>>I want to put a SetDirectory (?) command at the beginning of a >>>>notebook >>>>that will reset the working directory to the folder containing the >>>>notebook itself. >>>> >>>>Objective is to have the results of any Exports, OpenWrites, etc, >>>>executed within that notebook automatically be directed to that same >>>>folder -- even if I close the notebook, rename it in the Finder (in >>>>Mac >>>>jargon), and re-open it. >>>> >>>>Or, if I Copy or Move the notebook to a different folder and later >>>>open >>>>it there, Exports or OpenWrites should go to that new, different >>>>folder.