My Gui by Hotfoot
Designed for the end user or beginner. The user can access favorite text clips, text templates, files, folders, and hyperlinks with a GUI (contains 6 tabs and uses mostly listboxes). The user just needs to modify the files that are created by the script when run.
The script automatically creates a folder called 'My Gui' inside My Documents.
Folders called 'My Files' and 'My Templates' are created inside 'My Gui'.
'Group1.txt' and 'Group2.txt' files are created to hold AHK commands.
'TextClips.txt' is created to hold single-line text clips.
The 'My Templates' folder will hold txt files of multi-line text clips.
The 'My Files' folder is intended to hold shortcuts (or files) for easy access.
Hotkeys:
Control Shift A
or
Shift MButton
Code:
; Generated using SmartGUI Creator 3.5.1
#singleinstance, ignore ; leave original instance of script running if new instance is started
^+a:: ; Modify this hotkey to your liking
+MButton:: ; Also access GUI with combination Shift and Middle mouse button
; Suspend hotkeys to prevent accidentally triggering again - which causes an error
Suspend, On
; Create files and folders if they don't exist yet
IfNotExist, %UserProfile%\My Documents\My Gui
FileCreateDir, %UserProfile%\My Documents\My Gui
IfNotExist, %UserProfile%\My Documents\My Gui\TextClips.txt
{
FileAppend, Sample Text Clip, %UserProfile%\My Documents\My Gui\TextClips.txt
FileAppend, `nAnother Text Clip, %UserProfile%\My Documents\My Gui\TextClips.txt
FileAppend, `nThird Text Clip, %UserProfile%\My Documents\My Gui\TextClips.txt
}
IfNotExist, %UserProfile%\My Documents\My Gui\My Templates
FileCreateDir, %UserProfile%\My Documents\My Gui\My Templates
;;;;;;;;;;
; Create sample clip file. You may delete this command after you have tested it.
;;;;;;;;;;
IfNotExist, %UserProfile%\My Documents\My Gui\My Templates\Sample Clip File.txt
{
FileAppend, This text was pasted from 'Sample Clip File.txt'`nCreate your own text files`nand place them inside the`nMy Documents\My Gui\My Templates folder`nYou may delete this sample clip file `nand the associated commands in My Gui.ahk`nnow that you have tried it, %UserProfile%\My Documents\My Gui\My Templates\Sample Clip File.txt
}
;;;;;;;;;;
IfNotExist, %UserProfile%\My Documents\My Gui\My Files
FileCreateDir, %UserProfile%\My Documents\My Gui\My Files
IfNotExist, %UserProfile%\My Documents\My Gui\Group1.txt
{
FileAppend, Run C:\, %UserProfile%\My Documents\My Gui\Group1.txt
FileAppend, `nRun www.autohotkey.com, %UserProfile%\My Documents\My Gui\Group1.txt
Fileappend, `nRun "C:\Program Files\Internet Explorer\IEXPLORE.EXE" -new "http://www.autohotkey.com/", %UserProfile%\My Documents\My Gui\Group1.txt
}
IfNotExist, %UserProfile%\My Documents\My Gui\Group2.txt
{
Fileappend, Run %SystemRoot%\system32\notepad.exe, %UserProfile%\My Documents\My Gui\Group2.txt
Fileappend, `nRun D:\, %UserProfile%\My Documents\My Gui\Group2.txt
}
; End section for creating files and folders
Gosub, MyDisplay ; Go to Gui commands
Gui, Show, x230 y156 h344 w759, Menu: ; Display the Gui
SetTimer, DefaultFocus, 77 ; Timer to check which tab has focus
Return
;;;; Below are the commands for the buttons for each tab
TextClips:
if A_GuiControlEvent <> DoubleClick ; Do nothing when selection is single-clicked/changes
return
Button1: ; If the button is activated, then run the below commands
GuiControlGet, TextClips ; Retrieve the ListBox's current selection
clipboard = %TextClips% ; Copy selection to Clipboard
Gui, Destroy ; Remove Gui
sleep,200
send,^v ; Paste item
Suspend, Off
return
TemplateClips:
if A_GuiControlEvent <> DoubleClick ; Do nothing when selection is single-clicked/changes
return
Button2:
GuiControlGet, TemplateClips ; Retrieve the ListBox's current selection.
Gui, Destroy ; Remove Gui
; Now read each line and paste into previous window
FileRead, Contents, %UserProfile%\My Documents\My Gui\My Templates\%TemplateClips%
{
clipboard = %Contents%
sleep,44
send,^v
}
Suspend, Off
return
Group1:
if A_GuiControlEvent <> DoubleClick ; Do nothing when selection is single-clicked/changes
return
Button3: ; Run the below commands when button is activated
GuiControlGet, Group1 ; Retrieve the ListBox's current selection.
Gui, Destroy ; Remove Gui
; Copy current selection to a temporary ahk file and execute it
FileDelete, %UserProfile%\My Documents\My Gui\Temp.ahk
sleep,100
FileAppend, %Group1%, %UserProfile%\My Documents\My Gui\Temp.ahk
sleep,100
Run %UserProfile%\My Documents\My Gui\Temp.ahk
sleep,100
FileDelete, %UserProfile%\My Documents\My Gui\Temp.ahk
Suspend, Off
return
Group2:
if A_GuiControlEvent <> DoubleClick
return
Button4:
GuiControlGet, Group2
Gui, Destroy
; Copy current selection to a temporary ahk file and execute it
FileDelete, %UserProfile%\My Documents\My Gui\Temp.ahk
sleep,100
FileAppend, %Group2%, %UserProfile%\My Documents\My Gui\Temp.ahk
sleep,100
Run %UserProfile%\My Documents\My Gui\Temp.ahk
sleep,100
FileDelete, %UserProfile%\My Documents\My Gui\Temp.ahk
Suspend, Off
return
FileLinks:
if A_GuiControlEvent <> DoubleClick
return
Button5:
GuiControlGet, FileLinks ; Retrieve the ListBox's current selection.
Gui, Destroy ; Remove Gui
; If selection is a shortcut, get the file path and run the path
If ext in lnk
{
FileGetShortcut, %FileLinks%, target
Run, %target%,, UseErrorLevel
If ErrorLevel
MsgBox Could not open "%target%"
return
}
; If selection is not a shortcut, run the file instead
Run, %UserProfile%\My Documents\My Gui\My Files\%FileLinks%,, UseErrorLevel
if ErrorLevel
MsgBox Could not open "%FileLinks%"
Suspend, Off
return
DateFormats:
Calendar:
if A_GuiControlEvent <> DoubleClick
return
Button6:
GuiControlGet, DateFormats
Gui, Destroy
sleep,100
; Convert Date and Time according to user selection
If DateFormats = MM/dd/yy
FormatTime, TimeString, %calendar%,MM/dd/yy
If DateFormats = MMMM dd, yyyy
FormatTime, TimeString, %calendar%,MMMM dd, yyyy
If DateFormats = yyyy/MM/dd
FormatTime, TimeString, %calendar%,yyyy/MM/dd
If DateFormats = MMM dd, yyyy
FormatTime, TimeString, %calendar%,MMM dd, yyyy
If DateFormats = MMM dd, yyyy hh:mmtt
FormatTime, TimeString, %calendar%,MMM dd, yyyy hh:mmtt
clipboard = %TimeString% ; Copy formatted date to clipboard
send,^v ; Paste from clipboard
Suspend, Off
return
;;;;;;;;;;;;;;;;;
;Gui Commands
;;;;;;;;;;;;;;;;;
MyDisplay:
Gui, font, s11, Arial
Gui, Add, Tab, x6 y7 w740 h330, Text Clips|Template Clips|Files Group 1|Files Group 2|File Links|Date
Gui, Add, ListBox, x16 y37 w630 h300 vTextClips gTextClips
Gui, Add, Button, x656 y37 w80 h30 Default vButton1 gButton1, Paste
Gui, Tab, Template Clips
Gui, Add, ListBox, x16 y37 w630 h300 vTemplateClips gTemplateClips
Gui, Add, Button, x656 y37 w80 h30 vButton2 gButton2, Paste
Gui, Tab, Files Group 1
Gui, Add, ListBox, x16 y37 w630 h300 vGroup1 gGroup1
Gui, Add, Button, x656 y37 w80 h30 vButton3 gButton3, Enter
Gui, Tab, Files Group 2
Gui, Add, ListBox, x16 y37 w630 h300 vGroup2 gGroup2
Gui, Add, Button, x656 y37 w80 h30 vButton4 gButton4, Enter
Gui, Tab, File Links
Gui, Add, ListBox, x16 y37 w630 h300 vFileLinks gFileLinks
Gui, Add, Button, x656 y37 w80 h30 vButton5 gButton5, Enter
Gui, Tab, Date
Gui, Add, MonthCal, x36 y57 w250 h230 vcalendar gcalendar,
Gui, Add, ListBox, x296 y97 w230 h200 vDateFormats gDateFormats, MMM dd, yyyy||yyyy/MM/dd|MM/dd/yy|MMMM dd, yyyy|MMM dd, yyyy hh:mmtt
Gui, Add, Text, x296 y57 w90 h30, Format:
Gui, Add, Button, x536 y97 w100 h30 vButton6 gButton6, Insert
Gui, Submit
; Read text from files/folders to fill listboxes
Loop, read, %UserProfile%\My Documents\My Gui\TextClips.txt
{
%A_Index% = %A_LoopReadLine%
If A_Index = 1
GUIControl,, TextClips, |%A_LoopReadLine%|
Else
GUIControl,, TextClips, %A_LoopReadLine%
}
Loop, %UserProfile%\My Documents\My Gui\My Templates\*.*
{
%A_Index% = %A_LoopFileName%
If A_Index = 1
GUIControl,, TemplateClips, |%A_LoopFileName%|
Else
GUIControl,, TemplateClips, %A_LoopFileName%
}
Loop, read, %UserProfile%\My Documents\My Gui\Group1.txt
{
%A_Index% = %A_LoopReadLine%
If A_Index = 1
GUIControl,, Group1, |%A_LoopReadLine%|
Else
GUIControl,, Group1, %A_LoopReadLine%
}
Loop, read, %UserProfile%\My Documents\My Gui\Group2.txt
{
%A_Index% = %A_LoopReadLine%
If A_Index = 1
GUIControl,, Group2, |%A_LoopReadLine%|
Else
GUIControl,, Group2, %A_LoopReadLine%
}
Loop, %UserProfile%\My Documents\My Gui\My Files\*.*
{
%A_Index% = %A_LoopFileName%
If A_Index = 1
GUIControl,, FileLinks, |%A_LoopFileName%|
Else
GUIControl,, FileLinks, %A_LoopFileName%
}
return
;;;;;;
DefaultFocus: ; Change the default button according to currently displayed tab
ControlGetFocus, control, Menu:
If control = ListBox1
{
GuiControl, +Default, Button1
return
}
If control = ListBox2
{
GuiControl, +Default, Button2
return
}
If control = ListBox3
{
GuiControl, +Default, Button3
return
}
If control = ListBox4
{
GuiControl, +Default, Button4
return
}
If control = ListBox5
{
GuiControl, +Default, Button5
return
}
If control = ListBox6
{
GuiControl, +Default, Button6
return
}
return
;;;;;;;;;;
GuiClose:
GuiEscape:
Suspend, Off
Gui, Destroy
return