Autohotkey Gui Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
arpit12
Posts: 56
Joined: 10 Apr 2022, 04:19

Autohotkey Gui

Post by arpit12 » 11 Jun 2022, 03:06

Hi,
Is it possible in autohotkey to drag and drop the folder in gui and it will get the path and the content of the folder.

ananthuthilakan
Posts: 188
Joined: 08 Jul 2019, 05:37
Contact:

Re: Autohotkey Gui

Post by ananthuthilakan » 11 Jun 2022, 03:27

Code: Select all

gui,2: Add, text ,, Drop file
Gui,2: Show, w100 h100
return

2GuiDropFiles:
MsgBox, % A_GuiEvent
return



Esc::
ExitApp


arpit12
Posts: 56
Joined: 10 Apr 2022, 04:19

Re: Autohotkey Gui

Post by arpit12 » 11 Jun 2022, 03:36

Thanks @ananthuthilakan
How can i see the content of the folder?

ananthuthilakan
Posts: 188
Joined: 08 Jul 2019, 05:37
Contact:

Re: Autohotkey Gui

Post by ananthuthilakan » 11 Jun 2022, 03:42

Code: Select all

gui,2: Add, text ,, Drop file
Gui,2: Show, w100 h100
return

2GuiDropFiles:
MsgBox, % A_GuiEvent
Loop, Files, %A_GuiEvent%\*.*, FD  ; Include Files and Directories
MsgBox, % A_loopfilename
return



Esc::
ExitApp

https://www.autohotkey.com/docs/commands/LoopFile.htm

arpit12
Posts: 56
Joined: 10 Apr 2022, 04:19

Re: Autohotkey Gui

Post by arpit12 » 11 Jun 2022, 03:58

@ananthuthilakan
Just one more thing I want to add one Edit box in gui that shows the path of the folder and one button.
i tried adding like this

Code: Select all

Gui Add, Button, x31 y42 w80 h23, &OK
Gui Add, Edit, x78 y142 w120 h21
Gui Show, w200 h200, Window
Return
But then the drag box disappearing.

ananthuthilakan
Posts: 188
Joined: 08 Jul 2019, 05:37
Contact:

Re: Autohotkey Gui

Post by ananthuthilakan » 11 Jun 2022, 04:09

you missed out gui, 2: ,
2GuiDropFiles: there also you could see 2, that is Gui name

ananthuthilakan
Posts: 188
Joined: 08 Jul 2019, 05:37
Contact:

Re: Autohotkey Gui  Topic is solved

Post by ananthuthilakan » 11 Jun 2022, 04:17

Code: Select all


Gui,2: Add, Button, x31 y42 w80 h23, &OK
Gui,2: Add, Edit, x78 y142 w120 h21 vPath_of_file
Gui,2: Show, w200 h200, Window
Return


2GuiDropFiles:
MsgBox, % A_GuiEvent
GuiControl,2: , Path_of_file, % A_GuiEvent
Loop, Files, %A_GuiEvent%\*.*, FD  ; Include Files and Directories
MsgBox, % A_loopfilename
return



Esc::
ExitApp

you dont need gui name if you have only one gui in one application, but usually we will have more gui's in a single application :D

garry
Posts: 3770
Joined: 22 Dec 2013, 12:50

Re: Autohotkey Gui

Post by garry » 11 Jun 2022, 07:10

@ananthuthilakan thank you , just added also subfolders content

Code: Select all

Gui,2: Add, Edit, x10 y10 w670 h200 vPath_of_file
Gui,2: Show, w700 h250,Drag&Drop File or Folder
Return
;-----------------------
2GuiDropFiles:
Loop, Files, %A_GuiEvent%\*.*,FDR
  e .= A_loopfilename . "`r`n"
GuiControl,2: , Path_of_file,%e%  
return
;-----------------------
2Guiclose:
exitapp
;-----------------------

arpit12
Posts: 56
Joined: 10 Apr 2022, 04:19

Re: Autohotkey Gui

Post by arpit12 » 11 Jun 2022, 09:31

How can i assign action to the button like when button is clicked it will run some code?

Code: Select all

Gui, color, Black
Gui,2: Add, text ,y10, File Path :
Gui,2: Add, Edit, x70 y10 w300 h21 vPath_of_file
Gui,2: Add, Button, x70 y140 w120 h23 gsub1, FolderCreator
Gui,2: Add, Button, x210 y140 w120 h23 gsub2, Renamer
Gui,2: Add, Button, x70 y220 w120 h23 gsub3, JPG
Gui,2: Add, Button, x210 y220 w120 h23 gsub4, NotePad
Gui,2: Show, w400 h400, Script
Return


2GuiDropFiles:
GuiControl,2: , Path_of_file, % A_GuiEvent
Loop, Files, %A_GuiEvent%\*.*, FD  ; Include Files and Directories
MsgBox, % A_loopfilename
return

sub3:
{
MsgBox,64, Folder, Its Working
}

Esc::
ExitApp

I tried like this but its not working giving error in "gsub"

Also can anyone tell me the meaning of

Code: Select all

 e .= A_loopfilename . "`r`n"
.=
&
. "`r`n"
in this line

garry
Posts: 3770
Joined: 22 Dec 2013, 12:50

Re: Autohotkey Gui

Post by garry » 11 Jun 2022, 11:13

need a return after each gLabel / Label must exist

Code: Select all

;- nothing happens here in sub1/2/4 but goto-Label exists
sub1:
sub2:
sub4:
return
;-----
sub3:
msgbox, 262208,TEST ,SUB3 start TimeandDate in 5 seconds,5  ; info show for 5 seconds always on top 
try
run,https://www.timeanddate.com/
return
example from script above

Code: Select all

2GuiDropFiles:                ;- drop file or folder                   
Loop, Files, %A_GuiEvent%\*.*,FDR    ; loop for File/Folder/Subfolder
  e .= A_loopfilename . "`r`n"          ;- variable 'e' collect all readed files/folders and `r`n is end of line ( ascii CR=13 and LF=10 ) 
GuiControl,2: , Path_of_file,%e%     ;- show all these in GUI edit variable 'path_of_file'
return

arpit12
Posts: 56
Joined: 10 Apr 2022, 04:19

Re: Autohotkey Gui

Post by arpit12 » 11 Jun 2022, 12:03

Thanks you @garry it works

arpit12
Posts: 56
Joined: 10 Apr 2022, 04:19

Re: Autohotkey Gui

Post by arpit12 » 12 Jun 2022, 00:31

Hi, This is the code i m trying to works the problem is
1. I don't want to use any keystroke if there is any other way that be great.
2. part of code is not working but it works if I put in separate AHK file.

Code: Select all

	
	If (part.1 = "OldNavy")
	{
	FileMove, %A_LoopFilePath%, % file :="UV_" part.3 "." ext
	}	
Ongoing Code----------

Code: Select all

Gui, color, Black ; this is not working also.
Gui +AlwaysOnTop ; this is not working also.
Gui,2: Add, text ,y10, File Path :
Gui,2: Add, Edit, x70 y10 w300 h21 vPath_of_file
Gui,2: Add, Button, x70 y140 w120 h23 gsub1, FolderCreator
Gui,2: Add, Button, x210 y140 w120 h23 gsub2, Renamer
Gui,2: Add, Button, x70 y220 w120 h23 gsub3, JPG
Gui,2: Add, Button, x210 y220 w120 h23 gsub4, NotePad
Gui,2: Show, w400 h400, Script
Return


2GuiDropFiles:
GuiControl,2: , Path_of_file, % A_GuiEvent
dir := A_GuiEvent
return



sub1:
{
Send {c}
}
sub2:
sub3:

sub4:
return

;Function


c::
Loop, Files, %dir%\* copy.*
{ 	
	SplitPath, A_LoopFileName,,,, fnBare
	FileMove, %A_LoopFilePath%, % dir "\" RegExReplace(fnBare, " copy$", ".") A_LoopFileExt
}
Loop, Files, %dir%\*.png
{

	SplitPath, A_LoopFilePath, fn,, ext
	part := StrSplit(fn, "_")
	If !((part.1 = "OldNavy") || (part.1 = "UV"))
		{  
		If !FileExist(subdir := dir "\" part.1) 
		{
		FileCreateDir, %subdir%
		If ErrorLevel
		{
		MsgBox, 48, Error, An error occurred while creating the directory.
		Continue
		}
		}
		}   

	If (part.1 = "OldNavy")
	{
	FileMove, %A_LoopFilePath%, % file :="UV_" part.3 "." ext
	}	

}
Please if any one can have a look and help me.
Thank you

garry
Posts: 3770
Joined: 22 Dec 2013, 12:50

Re: Autohotkey Gui

Post by garry » 12 Jun 2022, 05:36

add 2:

Code: Select all

Gui,2:default
Gui,2: +AlwaysOnTop    
Gui,2: color, Black ,Gray  ; black is GUI , gray is edit ( as example )
;--
Gui,show
return
;--------------
2Guiclose:
Exitapp
;--------------
;...
;- use gLabel sub1 to run ( FolderCreator ) / not tested

Code: Select all

sub1:
;c::  ;- this removed 
Loop, Files, %dir%\* copy.*
{ 	
	SplitPath, A_LoopFileName,,,, fnBare
	;SplitPath,A_LoopFileName, name, dir, ext, name_no_ext, drive
	FileMove, %A_LoopFilePath%, % dir "\" RegExReplace(fnBare, " copy$", ".") A_LoopFileExt
}
Loop, Files, %dir%\*.png
{
;-----  continue script and add return at end
return

arpit12
Posts: 56
Joined: 10 Apr 2022, 04:19

Re: Autohotkey Gui

Post by arpit12 » 16 Jun 2022, 07:41

@garryHi,
As A_GuiEvent is giving the path of the folder in previous code how can I get path of the folder one folder down for example:
A_GuiEvent is giving path like C:\AHK\code
I want the path C:\AHK

garry
Posts: 3770
Joined: 22 Dec 2013, 12:50

Re: Autohotkey Gui

Post by garry » 16 Jun 2022, 13:24

example , path one back

Code: Select all

;- As A_GuiEvent is giving the path of the folder in previous code how can I get path of the folder one folder down for example:
;- A_GuiEvent is giving path like C:\AHK\code
;- I want the path C:\AHK
F1=C:\AHK\code
StringSplit,a,F1,`\
c:=(a0-1)           ;- back 1
loop,%c%
   F1new .= a%a_index% . (a_index < c ? "\" : "")
msgbox,%f1new%
return

arpit12
Posts: 56
Joined: 10 Apr 2022, 04:19

Re: Autohotkey Gui

Post by arpit12 » 16 Jun 2022, 14:05

@garry No what i meant is go to back by one folder. the path can be anything not a specific one.

garry
Posts: 3770
Joined: 22 Dec 2013, 12:50

Re: Autohotkey Gui

Post by garry » 17 Jun 2022, 07:30

example with a_guievent / path back -1 or without path back -1

Code: Select all

#warn
setworkingdir,%a_scriptdir%
;Gui,2: -dpiscale
Gui,2:Color,Black,Gray
Gui,2:Font,s12 cYellow,Lucida Console
;------------
Gui,2: Add, Edit  , x10  y10  w770  h200 -wrap vPath_of_file
Gui,2: Add, Edit  , x10  y240 w90   h27  -vscroll  vCount right readonly
Gui,2: Add, Edit  , x110 y240 w680  h27  -vscroll vPathSelected
Gui,2: Show, x100 y100 w800 h300,Drag&Drop File or Folder
Return
;-----------------------
2GuiDropFiles:
gosub,clear
x:=a_guievent
StringSplit,a,x,`\
C:=(a0-1)
loop,%c%
  d .= a%a_index% . (a_index < c ? "\" : "")   ;- path back -1  / example :  a_desktop\Test1 > new  a_desktop ( whole desktop ) 
;msgbox,D1=%d%  
;d:=x                                          ;- this without path back -1  a_desktop\Test1  ( only folder Test1 at desktop)
;msgbox,D2=%d%
GuiControl,2:,pathselected,%d%
Loop, Files, %d%\*.*,FD
  {
  i++
  e .= A_loopfilefullpath . "`r`n"
  }
GuiControl,2:,Path_of_file,%e%  
GuiControl,2:,count,%i%
return
;-----------------------
clear:
x:="",d:="",e:="",i:=0
GuiControl,2:,count
GuiControl,2:,Path_of_file
return
;-----------------------
;-----------------------
2Guiclose:
exitapp
;-----------------------

arpit12
Posts: 56
Joined: 10 Apr 2022, 04:19

Re: Autohotkey Gui

Post by arpit12 » 21 Jun 2022, 06:37

Hi, @garry
How can we show message in gui instead of normal message box that pop out.
How can i can count no of files it is copying and show that in gui message.
Also if possible display the time it took to perform that action.

garry
Posts: 3770
Joined: 22 Dec 2013, 12:50

Re: Autohotkey Gui

Post by garry » 03 Jul 2022, 13:51

a COPY example with windows robocopy

Code: Select all

;-created =20220703  
;- Drag & Drop a folder and copy to > F:\_ARPIT12 / used windows robocopy 
;- https://www.autohotkey.com/boards/viewtopic.php?f=76&t=105218
;-
#warn
#NoEnv
setworkingdir,%a_scriptdir%
Gui,2: -dpiscale
Gui,2:Color,Black,Black
Gui,2:Font,s12 cYellow,Lucida Console
wa:=A_screenwidth,ha:=A_screenHeight,xx:=100
;-
;----------- MAIN DESTINATION ------------------
HDD := "F"
if FileExist(HDD ":\")
 {
 DEST1  :="F:\_ARPIT12"         ;- << main destination / copies here Folder\subfolders\files
 ifnotexist,%dest1%
   filecreatedir,%dest1%
 }
else
 {  
 msgbox, 262208,Warning, HDD "%HDD%" not found.
 exitapp
 } 
;-----------------------------------------------
Menu,S1 ,add,EDIT_ThisScript         ,MH1
Menu,S2 ,add,OPEN_ThisFolder         ,MH2
Menu,S3 ,add,RELOAD                  ,MH3
menu,myMenuBar,Add,ThisScript              ,:S1
menu,myMenuBar,Add,ThisFolder              ,:S2
menu,myMenuBar,Add,RELOAD                  ,:S3
Gui,2:menu,MyMenuBar
recx:=""
dest2:=""
;-----------
text9:="SOURCE Drag & Drop only FOLDER"
x:=(wa*1)/xx,y:=(ha*1)/xx,w:=(wa*8)/xx
Gui,2:add,text,x%x% y%y% w%w%,%text9%
x:=(wa*9)/xx,y:=(ha*1)/xx,w:=(wa*40)/xx,h:=(ha*2.6)/xx
Gui,2:add,Edit, x%x%  y%y% w%w%  h%h% -vscroll vSOURCE1
;-
x:=(wa*1)/xx,y:=(ha*5)/xx,w:=(wa*15)/xx
Gui,2:add,text,x%x% y%y% w%w%,DESTINATION  :
x:=(wa*9)/xx,y:=(ha*5)/xx,w:=(wa*40)/xx,h:=(ha*2.6)/xx
Gui,2:add,Edit, x%x%  y%y% w%w%  h%h% -vscroll vDEST1x readonly,%dest1%
;-
x:=(wa*1)/xx,y:=(ha*10)/xx
Gui,2:Add, Text  , x%x%  y%y%          ,Folders=
x:=(wa*5)/xx,y:=(ha*10)/xx,w:=(wa*3)/xx,h:=(ha*2.6)/xx
Gui,2:Add, Edit  , x%x% y%y% w%w%   h%h%  -vscroll vCount1 right readonly
;-
x:=(wa*1)/xx,y:=(ha*14)/xx
Gui,2:Add, Text  , x%x%  y%y%         ,Files=
x:=(wa*5)/xx,y:=(ha*14)/xx,w:=(wa*3)/xx,h:=(ha*2.6)/xx
Gui,2:Add, Edit  , x%x% y%y% w%w%   h%h%  -vscroll vCount2 right readonly
;-
x:=(wa*1)/xx,y:=(ha*18)/xx,w:=(wa*6)/xx,h:=(ha*2.6)/xx
Gui,2:Add, Button  , x%x% y%y% w%w%   h%h%  gStart vBTStart,START
;-
x:=(wa*8)/xx,y:=(ha*18)/xx,w:=(wa*15)/xx,h:=(ha*2.6)/xx
Gui,2:Add, Edit  , x%x% y%y% w%w%   h%h%  -vscroll vText1 readonly
;-
x:=(wa*24)/xx,y:=(ha*18)/xx,w:=(wa*6)/xx,h:=(ha*2.6)/xx
Gui,2:Add, Button  , x%x% y%y% w%w%   h%h%  gClear vBTclear,Clear
;-
x:=(wa*31)/xx,y:=(ha*18)/xx,w:=(wa*6)/xx,h:=(ha*2.6)/xx
Gui,2:Add, Button  , x%x% y%y% w%w%   h%h%  gFolder vBTFolder,FOLDER
;-
Gui,2:add,text,x0 y0 w0 h0 vT1
x:=(wa*20)/xx,y:=(ha*20)/xx,w:=(wa*50)/xx,h:=(ha*24)/xx
Gui,2:Show, x%x% y%y% w%w% h%h%,COPY
GuiControl,2:Disable,btstart
GuiControl,2:Disable,btfolder
GuiControl,2:Disable,btClear
Return
;-----------------------
2Guiclose:
if (recx=1)
  {
  msgbox, 262208,COPY ,COPY is running
  return
  }
else
  exitapp
;-----------------------
2GuiDropFiles:
AAC:=a_guievent
SplitPath,AAC, name, dir, ext, name_no_ext, drive
if ext<>
  return
Gui,2:submit,nohide
GuiControl,2:,Text1,
GuiControl,2:,count1,
GuiControl,2:,count2,
dest2:=dest1 . "\" . name
GuiControl,2:,Source1,%AAC%
GuiControl,2:,dest1x,%dest2%
;-----
filesx:=""
foldersx:=""
Loop, Files, %aac%\*.*, FR
	Filesx := A_Index
Loop, Files, %aac%\*.*, DR
	Foldersx := A_Index
GuiControl,2:,count1,%foldersx%
GuiControl,2:,count2,%filesx%
GuiControl,2:Enable,btstart
return
;----------------------
Start:
Gui,2:submit,nohide
if (source1="")
  {
  msgbox, 262208, ,SOURCE is not selected
  return
  }
GuiControl,2:,Text1,Copy is running .....
starttime  := A_TickCount
recx=1
runwait, %comspec% /c robocopy "%source1%" "%dest2%" /XO /E /UNICODE,,hide       ;- <<<< robocopy running
recx=0
aat:=(A_TickCount - starttime)//1000 
GuiControl,2:,Text1,COPY FINISHED in %aat% seconds
aat=
source1=
AAC=
GuiControl,2:Disable,btstart
GuiControl,2:Enable,btfolder
GuiControl,2:Enable,btClear
GuiControl,2: Focus, T1
return
;--------------------
clear:
AAC=
source1=
GuiControl,2:,Text1,
GuiControl,2:,Source1,
GuiControl,2:,count1,
GuiControl,2:,count2,
GuiControl,2:,dest1x,%dest1%
GuiControl,2:Disable,btstart
GuiControl,2:Disable,btfolder
GuiControl,2:Disable,btClear
return
;--------------------
Folder:
try
 run,%dest2%
return
;--------------------
mh1:
editorx1=C:\Program Files\Notepad++\notepad++.exe
ifnotexist,%editorx1%
  editorx1:=""
ifexist,%editorx1%
    run,%editorx1% "%a_scriptfullpath%"
else
  run, notepad "%a_scriptfullpath%"
return
;-----------
mh2:
run,%a_scriptdir%
return
;-----------
mh3:
if (recx=1)
  {
  msgbox, 262208,COPY ,COPY is running
  return
  }
else
 reload
return
;-----------
;=====================================================================

Post Reply

Return to “Ask for Help (v1)”