AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to Find Current Working Directory of Active Window?

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
RobertMeta



Joined: 10 May 2009
Posts: 9

PostPosted: Sun May 10, 2009 8:53 pm    Post subject: How to Find Current Working Directory of Active Window? Reply with quote

I want to be able to find the current working directory of the active window.

This would allow me to have Firefox focused, and hit a keybinding, and open a console or explorer window to the C:\Program Files\Mozilla Firefox directory.

Or, more importantly, when editing files with my favorite text editor, which changes the working directory to that of my current file, it lets me simply hit my keybinding to either open explorer or a console right where I am working.

Thanks in advance for any assistance.
Back to top
View user's profile Send private message
SoLong&Thx4AllTheFish



Joined: 27 May 2007
Posts: 4999

PostPosted: Tue May 12, 2009 7:54 pm    Post subject: Reply with quote

GetCommandLine
http://www.autohotkey.com/forum/viewtopic.php?t=16575
use the A parameter with WinGet for active window

Alternatively you may try use WinTitle for applications that
display the filepath in the windows title.
_________________
AHK Wiki FAQ
TF : Text files & strings lib, TF Forum
Back to top
View user's profile Send private message
RobertMeta



Joined: 10 May 2009
Posts: 9

PostPosted: Wed May 13, 2009 4:57 am    Post subject: Reply with quote

Not exactly what I need, but thank you very much. That put me on the right path, I can use a DllCall to GetEnviromentVariable (specifically, the context variable) and I think that will work.

I will post the code once I get it working.

The reason that getting the command line is not a solution, is I need it to follow the app as the app changes it local context (working directory). Just because I started with c:\foo.exe doesn't mean I am still in c:\
Back to top
View user's profile Send private message
badmojo



Joined: 11 Nov 2005
Posts: 202

PostPosted: Fri May 15, 2009 5:25 pm    Post subject: Reply with quote

you can try shimanov's code from this thread here and also check out this working example.
Back to top
View user's profile Send private message
RobertMeta



Joined: 10 May 2009
Posts: 9

PostPosted: Wed May 27, 2009 10:36 pm    Post subject: Worst Example Ever... Reply with quote

I fear I gave the worst example ever with Firefox. Let me use a much better one, cmd.exe

Let say, I run cmd.exe and do "cd c:\users\robertmeta\projects\personal".

The path is: C:\Windows\system32\cmd.exe

The command line is: "C:\Windows\system32\cmd.exe"

The current directory is: "c:\Users\robertmeta\projects\personal\"

The "current directory" is the data I want to extract. Every application has one -- and the apps I want to use this hotkey in a lot (explorer, vim, etc) keep it set properly.

I currently get exactly the functionality I need for it from HoeKey -- but I want AutoHotKey to do everything I need. Smile
Back to top
View user's profile Send private message
SoLong&Thx4AllTheFish



Joined: 27 May 2007
Posts: 4999

PostPosted: Thu May 28, 2009 1:42 pm    Post subject: Reply with quote

Not sure if this will help you but you can try http://www.nirsoft.net/utils/opened_files_view.html (I had the idea once to use this to create a script to save a "workspace" e.g. save all open files in all applications to a txt file so I can "reload" that particular workspace and continue with all the files I have open) use can use the cmd line switches to output to a file for further processing it works with a CMD.exe
_________________
AHK Wiki FAQ
TF : Text files & strings lib, TF Forum
Back to top
View user's profile Send private message
RobertMeta



Joined: 10 May 2009
Posts: 9

PostPosted: Fri May 29, 2009 4:23 am    Post subject: Reply with quote

I have actually "solved" this sorta via a few third party apps, and I can always use the ultra-small Hoekey which has it native built in.

Obviously, I want a pure way to do it, as in pure Autohotkey. As I continue to research, I think I have found one of the issues. I believe that the current working directory is per THREAD not per PROCESS.
Back to top
View user's profile Send private message
badmojo



Joined: 11 Nov 2005
Posts: 202

PostPosted: Fri May 29, 2009 6:47 am    Post subject: Reply with quote

RobertMeta wrote:
I have actually "solved" this sorta via a few third party apps, and I can always use the ultra-small Hoekey which has it native built in.

if you don't mind, can you show how to do this via Hoekey?
Back to top
View user's profile Send private message
RobertMeta



Joined: 10 May 2009
Posts: 9

PostPosted: Fri May 29, 2009 10:49 pm    Post subject: Reply with quote

@t=Run|powershell -noexit -command "cd \"%c\""
@e=Run|explorer "%c"

alt-t and alt-e will open a terminal or explorer where-ever I am, as a developer, it is a life safer.

I am in vim, working in directory c:\foo\bar\blah -- and I just need to run the current file in a terminal, I can just hit alt-t to open a term, already in c:\foo\bar\blah
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group