AutoHotkey Community

It is currently May 27th, 2012, 10:27 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 

Can you see yourself actually using this, or does it seem like a "novelty" script?
You're kidding, right? This is the best thing since chicken teriyaki.
Ya, sure, I'd use this.
Meh, so-so. I probably won't use it for long.
Cool script and all, but I don't need it.
I don't think it's a very good idea; see my reason below.
This poll has way too many options. Why is there a poll, anyway?
You may select 1 option

View results
Author Message
 Post subject: Clip.Ahk & Cmd.Ahk
PostPosted: February 12th, 2005, 5:48 am 
Offline

Joined: November 13th, 2004, 4:08 am
Posts: 2951
Location: Minnesota
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! :twisted:

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 :D )!

Edit/Changelog:

Fixed bug in Clip.Ahk (Thanks toralf)


Last edited by jonny on February 14th, 2005, 5:43 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 12th, 2005, 6:08 am 
Offline

Joined: November 13th, 2004, 4:08 am
Posts: 2951
Location: Minnesota
Hmm... first bug I just found now, while doing a multi-directory operation; if you do multiple commands (via the && operator), the last one is the one that shows in the edit by default. I might fix this sometime, like by parsing for && and doing something different, but it's not that big of a deal right now.

Also, another "landmark" here is the first planned feature for each tool:

Cmd.Ahk: Command history.

Clip.Ahk: Clipboard history.

Aren't I creative.

P.S. In case you hadn't figured out, commands like "cd" will have no effect alone, since the interpreter is started and closed for every operation. You can get around this be either using absolute paths in all the parameters, or using the folder field I included for your convenience (the smaller one to the left). Cmd.Ahk automagically does a cd to the directory in that field before doing the other stuff.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 14th, 2005, 9:43 am 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
A Bug in line 47 of clip.ahk, the line should be:

Code:
menu,Clipboard,add,Run Clipboard,clipboardrun


The ",clipboardrun" was missing.

I'll test the scripts and see what I can use.

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject: cmd.ahk and clip.ahk
PostPosted: September 16th, 2006, 11:03 pm 
Offline

Joined: September 16th, 2006, 11:00 pm
Posts: 4
Can someone please enlighten me?
What are these for?
I tried running them and reading the AHK files. There was no clue.
What do these do?

:?:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 17th, 2006, 10:22 am 
Offline

Joined: August 8th, 2006, 3:55 pm
Posts: 49
jonny wrote
Quote:
Clip.Ahk: A small utility for use as anything. Do not let the name limit your possibilities.
I also would be glad to have an explanation.
Is it possible to get an explanation ( or one or two simple examples for its usability)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 5th, 2006, 5:23 am 
Offline

Joined: November 13th, 2004, 4:08 am
Posts: 2951
Location: Minnesota
clip.ahk is really just supposed to be an extra window to put stuff in - notes to yourself, snippets of code or messages, phone numbers, you name it. I don't even know why I posted these scripts now, heh.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: XX0 and 20 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group