We have A_WorkingDir for accessing the working directory of the current script.
But is there also some method for querying the working directory associated with the active window?
Purpose
I have written a script that opens one of several programs in the directory of the file opened in the current window (cmd.exe, explorer, Cygwin bash), or opens the opened file in Emacs.
Technical background
For programs, where this is viable, I extract the path of the file from the window title. Often programs have patterns such as "E:\Dropbox\CurrentProject\manual.lyx - LyX", which can easily be used for this. Some can be configured to allow this, e.g. by setting (setq frame-title-format "%f") in Emacs or setting FullPathInTitle = true in SumatraPDF.
In other programs however, this isn't possible.
I know, that programs can set a current working directory, that is then used as the default root directory for resolving relative file paths and executing subprocesses (in cmd.exe/powershell/bash the cd command,in Python os.chdir()). On the C++ level, it seems to be possible, but hackish. From within AutoHotkey (or Python3 for that matter), I have no idea how to do it.
Changes are though, that the programs internally don't set the working directory to the parent of the opened file; Would still be interesting as a possible fallback, IF they do.
Get working directory of a window's process?
Re: Get working directory of a window's process?
- There's this script:
[SOLVED]get other process's working dir - Page 3 - Ask for Help - AutoHotkey Community
https://autohotkey.com/board/topic/8530 ... ntry544650
- You can use regular AutoHotkey v1.1, however, you need a 32-bit/64-bit dll (see the link below), and you need to run 32-bit/64-bit AutoHotkey to match the process.
- I wrote a version of the function that doesn't require including scripts.
how to dll Inject - Page 2 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 80#p171580
- Here I list various techniques for getting the path of the active file from different programs.
Get path of active window's directory - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=38680
[SOLVED]get other process's working dir - Page 3 - Ask for Help - AutoHotkey Community
https://autohotkey.com/board/topic/8530 ... ntry544650
- You can use regular AutoHotkey v1.1, however, you need a 32-bit/64-bit dll (see the link below), and you need to run 32-bit/64-bit AutoHotkey to match the process.
- I wrote a version of the function that doesn't require including scripts.
how to dll Inject - Page 2 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 80#p171580
- Here I list various techniques for getting the path of the active file from different programs.
Get path of active window's directory - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=38680
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Who is online
Users browsing this forum: DiegoSouto, Rohwedder, Sniperman and 397 guests