Copy file name from inactive window title Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
timoshina
Posts: 67
Joined: 06 Jun 2017, 12:45

Copy file name from inactive window title

24 May 2018, 20:49

Hello guys! I've been working on a my script and I'm stuck at its final stage. . :facepalm:
I have a program in which I import a file example.jpg, do a bunch of actions and export it as example.png (file has to have same name). This program in a "save as" window, leaves the file name box empty for some reason, in which I have to type "example" & click the save button. In a background I have main program's window which has this title: (note title changes to the below name as soon as save as dialog appears)
C:\Users\timoshina\Desktop\DONE\example.jpg ahk_class Afx:400000:b:10003:6:18f00bb ahk_exe Program.exe
How can I copy only the "example" from the inactive window's title?
Here is the part of a code:

Code: Select all

#h:: ; test hotkey
SetTitleMatchMode, RegEx

WinWaitActive, Save As ahk_class #32770
IfWinExist, ahk_class Afx:400000:b:10003:6:

; copy file name without extention to clipboard

Send ^v
controlclick, Button2, Save As ahk_class #32770

return

AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Copy file name from inactive window title

24 May 2018, 22:37

timoshina wrote:Hello guys! I've been working on a my script and I'm stuck at its final stage. . :facepalm:
I have a program in which I import a file example.jpg, do a bunch of actions and export it as example.png (file has to have same name). This program in a "save as" window, leaves the file name box empty for some reason, in which I have to type "example" & click the save button. In a background I have main program's window which has this title: (note title changes to the below name as soon as save as dialog appears)
C:\Users\timoshina\Desktop\DONE\example.jpg ahk_class Afx:400000:b:10003:6:18f00bb ahk_exe Program.exe
How can I copy only the "example" from the inactive window's title?
Here is the part of a code:

Code: Select all

#h:: ; test hotkey
SetTitleMatchMode, RegEx

WinWaitActive, Save As ahk_class #32770
IfWinExist, ahk_class Afx:400000:b:10003:6:

; copy file name without extention to clipboard

Send ^v
controlclick, Button2, Save As ahk_class #32770

return

First you would do

WinGetTitle, OutVar, Save As ahk_class #32770

Next you will use regex on OutVar (My guess was that everything until the filename.jpg stays the same.

RegExMatch(OutVar, "(?<=C:\\Users\\timoshina\\Desktop\\DONE\\).+?(?=\.jpg)", results)

clipboard := % results

There might be shorter ways to do this but this is what I would try
timoshina
Posts: 67
Joined: 06 Jun 2017, 12:45

Re: Copy file name from inactive window title

24 May 2018, 23:45

AHKStudent wrote: First you would do

WinGetTitle, OutVar, Save As ahk_class #32770

Next you will use regex on OutVar (My guess was that everything until the filename.jpg stays the same.

RegExMatch(OutVar, "(?<=C:\\Users\\timoshina\\Desktop\\DONE\\).+?(?=\.jpg)", results)

clipboard := % results

There might be shorter ways to do this but this is what I would try
Thanks, i will try that in the morning. :)
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Copy file name from inactive window title  Topic is solved

24 May 2018, 23:53

One way:

Code: Select all

q:: ;get active window title (a path is expected), split path to get name/name no ext
WinGetTitle, vWinTitle, A
SplitPath, vWinTitle, vName, vDir, vExt, vNameNoExt, vDrive
MsgBox, % vName
MsgBox, % vNameNoExt
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
timoshina
Posts: 67
Joined: 06 Jun 2017, 12:45

Re: Copy file name from inactive window title

26 May 2018, 12:12

jeeswg wrote:One way:

Code: Select all

q:: ;get active window title (a path is expected), split path to get name/name no ext
WinGetTitle, vWinTitle, A
SplitPath, vWinTitle, vName, vDir, vExt, vNameNoExt, vDrive
MsgBox, % vName
MsgBox, % vNameNoExt
return
Holy hotkeys, dude! Thank you! It's so simple when you know it :0)
AHKStudent wrote:
Thanks for the try. You helped me with "clipboard := %" 8-)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Araphen, Dobbythenerd1, Draken and 325 guests