Please be honest on the poll!
Criticism is more helpful than "Shit this script rocks, bye now!"
Clip.Ahk: A small utility for use as anything. Do not let the name limit your possibilities. For those times when all you really need is an edit control...
Cmd.Ahk: A not-as-small-but-still-pretty-dang-tiny tool for the command interpreter. In short, it's a frontend for it, bringing the world of AHK Gui's to your own custom prompt.
Requires gclip
I must confess I've used these for a while. I just recently thought of posting them, so I undid all the damage I had done to it's usability and cleaned it up. They may seem like they'd be easy to code, but getting resizing to work was a bitch. Oh well. Have fun with it.
Oh, by the way, I must emphasize that these are meant to be
fully customizable. If you do not customize and tweak it until you're forced to stop for fear of developing RSI, you haven't gotten enough out of your Cmd.Ahk/Clip.Ahk. In fact, the only extra "features" I included on these tools were to demonstrate and encourage, and I won't be surprised at all if the first thing most people choose to do is remove some of them. Customize, or feel Jonny's wrath!
Code:
; This code is way easier to read
; with syntax highlighting because
; of all the comments, so if you plan
; to read 'em all right now I'd
; suggesting pasting it into your
; editor of choice.
; If you change the singleinstance
; setting, the "New Instance" option
; will be affected. Also, I'd recommend
; leaving notrayicon on, as it already
; has a taskbar icon.
#singleinstance off
#notrayicon
;==============File Menu==============
menu,File,add,New &Instance,filenewi
menu,File,add,Clip.&Ahk,fileclip
menu,File,add
menu,File,add,Config&ure,editscript
menu,File,add,&Reload,filereload
menu,File,add,E&xit,fileexit
;=====================================
;===========Folder Sub-Menu===========
menu,Folder,add,&Open,folderopen
menu,Folder,add,&Clear,folderclear
;=====================================
;==============Edit Menu==============
menu,Edit,add,&Leave Stdout on Clipboard,editset
menu,Edit,add,&Clear Fields,editclear
menu,Edit,add
menu,Edit,add,&Folder,:Folder
;=====================================
menu,Menubar,add,&File,:File
menu,Menubar,add,&Edit,:Edit
menu,Menubar,add,&Tray,:TRAY
gui,menu,Menubar
; If you're confused by the double
; input boxes, the first one is for
; a folder and is NOT cleared after
; the command. The second one is for
; the command itself, and IS cleared.
; Also note that if +Resize is in
; effect, the resizing routine lower
; down will run when the script starts,
; so any positioning and sizing options
; set here will be overwritten.
;===========Main Controls=============
gui,add,edit,readonly vcmdedit w600 h450
gui,add,edit,vcmdfolder
gui,add,edit,vcmdfield
;=====================================
; The button below is so an ~Enter hotkey
; isn't necessary. You can set one if you want.
gui,add,button,default hidden gsubmit x10 y10 w1 h1
; If you want better control over the position,
; size, etc. of your controls, you might want to
; remove this and the resizing routine, which
; also runs at startup.
gui,+resize
; Finally, adjust coordinates and window size
; here. And something else too... But I don't
; know why you'd want to change that. :-D
gui,show,center,Cmd.Ahk
return
; Open a new instance. Usually not
; necessary, unless you don't like
; Clip.Ahk, but it's there.
filenewi:
run,"%A_ScriptFullPath%"
return
; Opens Clip.Ahk or activates it
; if it's already running. It has to
; be in this script's dir or "path" to
; work right.
fileclip:
ifwinexist,Clip.Ahk
winactivate
else
run,"%A_ScriptDir%\clip.ahk"
return
; Handy for development. I used it a lot
; while making this, you might find it
; nice for configuring/tweaking.
filereload:
reload
return
; I quickly found an easier way
; was needed to input a folder.
folderopen:
fileselectfolder,folder,,,Cmd.Ahk
guicontrol,,cmdfolder,%folder%
return
; Clears the folder edit.
folderclear:
guicontrol,,cmdfolder,
return
editset:
menu,Edit,togglecheck,&Leave Stdout on Clipboard
if toggleclip = 1
toggleclip = 0
else if toggleclip = 0
toggleclip = 1
else
toggleclip = 1
return
; Runs the clipboard through AHK's handling
; of it, transforming binary data to it's
; full path and filename.
editconv:
clipboard = %clipboard%
return
; Clears both controls. Remove the second
; line if you're more accustomed to
; "Shift+Home, Delete" like I am.
editclear:
guicontrol,,cmdedit,
guicontrol,,cmdfield,
return
; Opens this script for editing.
editscript:
edit
return
; If you want it resizable and still want
; to tweak control positions, roll up
; your sleeves and get ready for this part.
; I'll try to explain...
guisize:
; WARNING: These are based on the margins,
; which in turn are based on the system
; fonts. If those are different on your
; PC, then these will need adjusting. "20"
; is twice the margin width, and "39" is
; twice the height plus one.
new_w := (A_GuiWidth - 20)
new_h := (A_GuiHeight - 39)
; An offset of 30 from the bottom.
field_y := (A_GuiHeight - 30)
guicontrol,move,cmdedit,w%new_w% h%new_h%
new_w := (new_w / 3)
guicontrol,move,cmdfolder,w%new_w% y%field_y%
new_x := (new_w + 10)
new_w := (new_w * 2)
guicontrol,move,cmdfield,w%new_w% y%field_y% x%new_x%
return
; "Enter" runs this, because the default
; button was pressed. (The wee hidden one.)
submit:
gui,submit,nohide
guicontrol,,cmdedit,Working...
; This code allows you to set your
; working directory in the left-hand
; field. Internally, it adds a "cd"
; command at the beginning.
if cmdfolder <>
cmdfield = cd "%cmdfolder%" && %cmdfield%
; Cache the clipboard.
cache = %clipboard%
; An error message that will show unless
; the clipboard is replaced with stdout.
clipboard = An error occurred.
; /d prevents autoruns to speed up performance,
; /c quits it after it's done executing,
; | gclip pipes the output to the clipboard...
runwait,cmd /d /c %cmdfield% | gclip,,hide
; ...where it's put on cmdedit.
guicontrol,,cmdedit,%clipboard%
; The command field is cleared.
guicontrol,,cmdfield,
; Restore the clipboard. (Doesn't restore
; binary data due to AHK limitations.)
if toggleclip = 0
clipboard = %cache%
; Clear the cache so if the clipboard
; was huge it doesn't sap your memory
; any longer.
cache =
return
; That's all, folks! ;-)
guiclose:
fileexit:
exitapp
Code:
; Much of this code is similar to Cmd.Ahk's,
; so I won't make any redundant comments.
#singleinstance off
#notrayicon
; Thank Rajat for the cool idea of a script
; using itself as an INI. The "LastPos" stuff
; is just an example of configuration, if
; you find it annoying it's very easy to
; remove it.
; WARNING: If you compile this, be sure
; to remove the INI section and all commands
; pertaining to it.
/*
[LastPos]
PosY=
PosX=
[LastSize]
PosW=
PosH=
*/
onexit,exitsub
iniread,posy,%a_scriptfullpath%,LastPos,PosY,
iniread,posx,%a_scriptfullpath%,LastPos,PosX,
iniread,posw,%a_scriptfullpath%,LastSize,PosW,
iniread,posh,%a_scriptfullpath%,LastSize,PosH,
;==============File Menu==============
menu,File,add,New &Instance,filenewi
menu,File,add,Cmd.&Ahk,filecmd
menu,File,add
menu,File,add,&Open...,fileopen
menu,File,add
menu,File,add,Config&ure,editscript
menu,File,add,&Reload,filereload
menu,File,add,E&xit,fileexit
;=====================================
;===========Clipboard Menu============
menu,Clipboard,add,Run Clipboard,clipboardrun
menu,Clipboard,add,Convert Clipboard to &Path,clipboardpath
;=====================================
menu,Menubar,add,&File,:File
menu,Menubar,add,&Clipboard,:Clipboard
menu,Menubar,add,&Tray,:tray
gui,menu,Menubar
gui,add,edit,veditid multi
gui,+Resize
; Only sets the positions if the
; variables aren't blank. Due to
; the nature of the script, if
; one isn't blank, they all won't
; be blank, and vice versa.
if posx <>
gui,show,x%posx% y%posy% w%posw% h%posh%,Clip.Ahk
; Otherwise, default to center.
else
gui,show,center,Clip.Ahk
return
guisize:
; Efficient use of variables! ;-)
posw := (a_guiwidth - 20)
posh := (a_guiheight - 12)
guicontrol,move,editid,w%posw% h%posh%
return
filenewi:
run,"%A_ScriptFullPath%"
return
filecmd:
ifwinexist,Cmd.Ahk
winactivate
else
run,"%A_ScriptDir%\cmd.ahk"
return
fileopen:
; Feel free to add more file types
; if you wish, or set it to All Files.
; I was only trying to illustrate
; that it can only be used with text files.
fileselectfile,file,3,Clip.Ahk,Text Files (*.txt; *.log; *.ahk)
fileread,file,%file%
guicontrol,,editid,%file%
return
filereload:
reload
return
editscript:
edit
return
clipboardrun:
; Betcha didn't see this coming.
run,%clipboard%
return
clipboardpath:
; Run the clipboard through AHK so it
; gets automagically converted to it's
; path. Obviously, only works on binary.
clipboard = %clipboard%
return
guiclose:
fileexit:
exitsub:
settitlematchmode,3
wingetpos,posx,posy,posw,posh,Clip.Ahk
iniwrite,%posx%,%a_scriptfullpath%,LastPos,PosX
iniwrite,%posy%,%a_scriptfullpath%,LastPos,PosY
iniwrite,%posw%,%a_scriptfullpath%,LastSize,PosW
iniwrite,%posh%,%a_scriptfullpath%,LastSize,PosH
exitapp
Don't be afraid to post modified versions of this (especially if they fix bugs

)!
Edit/Changelog:
Fixed bug in Clip.Ahk (Thanks toralf)