 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
olaf
Joined: 20 Apr 2005 Posts: 25
|
Posted: Tue Jun 28, 2005 9:23 am Post subject: gnugoo |
|
|
gnugoo v.26
You'll see that the script has got some clunk, by creating a temp file, reading it, then deleting it, when using diff, ls, or grep.
Requirements: whichever bins you want to use from http://gnuwin32.sourceforge.net/ .
This script currently uses diff, ls, xpdf, bzip2, bunzip2, grep, and pngutils.
xpdf is also at (homepage) http://www.foolabs.com/xpdf/.
The most frustrating bug, and maybe someone has a suggestion, is that really long filenames or long directory names and filenames will cause script errors for diff, ls, and grep. When running a bin manually through a command prompt, this does not happen, and is not an issue, so I don't think it is a bug within the binaries. I also don't think the bug is with ahk.
The pdfimages will use the filename for the image root name, unless
you type in something.
Don't be surprised if you see some of your code.
Two settings need to be set at the top.
The TextEditor is only for opening what's in the editbox.
gnugoo26.ahk
| Code: |
; gnugoo26
gnubins = X:\path\to\gnuwin32\bins
TextEditor = C:\Program Files\favorite\editor.exe
Gosub, Mogoostuff
Gui, +Resize
Gui, 1:Add, Radio, x5 y14 vdiffit, &Diff
Gui, 1:Add, Radio, x64 y14 vlsit, &ls
Gui, 1:Add, Radio, x210 y14 vpdf2txtit, &pdftotext
Gui, 1:Add, Radio, x210 y58 Section vpdfimagesit, pd&fimages
Gui, 1:Add, Radio, ys-44 x+1 vpdfinfoit, pdfi&nfo
Gui, 1:Add, Radio, x345 y14 Section vbzit, &bzip2
Gui, 1:Add, Radio, xs vbunzit, b&unzip2
Gui, 1:Add, Radio, x415 y15 vgrepit, gr&ep
Gui, 1:Add, Checkbox, x7 y31 Section vdiffu Checked, -u
Gui, 1:Add, Checkbox, xs vdiffr, -&r Rec
;Gui, 1:Add, Text, x35 y56, Rec
Gui, 1:Add, Checkbox, xs vdiffq, -q
Gui, 1:Add, Checkbox, x65 y32 Section vlslg Checked, -g Long Format - Date
Gui, 1:Add, Checkbox, xs vlsG Checked, -G No Group info
Gui, 1:Add, Checkbox, xs vlsA Checked, -A Almost all - no dir dots
Gui, 1:Add, Checkbox, xs vlsR Checked, -R Recursi&ve
Gui, 1:Add, Checkbox, x211 y34 vpdf2txtlayout, -lay&out
Gui, 1:Add, Checkbox, x211 y76 Section vpdfimagesjpg Checked, -&j Jpeg if possible
Gui, 1:Add, Edit, xs w50 Section vimagerootname, %PdfNameNoExt%
Gui, 1:Add, Text, ys+5, Image Root Name
Gui, 1:Add, Checkbox, x417 y35 Section vgrepi Checked, -i Case &insensitive
Gui, 1:Add, Checkbox, xs vgrepr Checked, -r R&ecursive
Gui, 1:Add, Edit, xs Section vgrepbox
Gui, 1:Add, Text, ys+5 Section, Grep Search
;Gui, 1:Add, Button, ys-5 x+-60 Hidden gGrepSearchHidden,
Gui, 1:Add, Button, x200 y130 w125 h27, &Goo
Gui, 1:Add, Button, x345 y130, Cle&ar
Gui, 1:Add, Button, x395 y130 Default, &Quit
; Gui, 1:Add, Checkbox, x365 y128 vdelout Checked, Auto Delete`nTemp File
Gui, 1:Add, Button, x450 y130 gOpenmogoo, &Mogoo
Gui, 1:Add, Button, x520 y130 gSaveoutbox, &Save
Gui, 1:Add, Button, x+25 gOpenInEditor, &Open
Gui, Font, S10 CDefault Norm, Verdana
Gui, 1:Add, Edit, x5 y175 w650 R15 vPostbox HScroll -Wrap
Gui, Font,,
; Gui, Show, w450 h400, GnuGoo
Gui, 1:Show,, GnuGoo
Return
Saveoutbox:
GuiControlGet, Postbox ; Retrieve the contents of the Edit control.
;if Postbox =
;msgbox, nothing
;else
FileSelectFile, SelectedFileName, S16,, Save File, Text Documents (*.txt)
if SelectedFileName = ; No file selected.
return
CurrentFileName = %SelectedFileName%
Gosub SaveCurrentFile
return
SaveCurrentFile: ; Caller has ensured that CurrentFileName is not blank.
IfExist %CurrentFileName%
{
FileDelete %CurrentFileName%
if ErrorLevel <> 0
{
MsgBox The attempt to overwrite "%CurrentFileName%" failed.
return
}
}
FileAppend, %Postbox%, %CurrentFileName% ; Save the contents to the file.
; Upon success, Show file name in title bar (in case we were called by FileSaveAs):
;Gui, Show,, %CurrentFileName%
return
OpenInEditor:
Gui, Submit, NoHide
OpenTmpName = opentmptxt.txt
If postbox is space
{
msgbox, Nothing to open.
return
}
FileAppend, %Postbox%, %TEMP%\%OpenTmpName%
RunWait, "%TextEditor%" %TEMP%\%OpenTmpName%
FileDelete, %TEMP%\%OpenTmpName%
return
ButtonGoo:
Gui, Submit, NoHide ; Remove NoHide to hide the GUI here
if (diffit)
{
Exec = %gnubins%\diff.exe
outname = diffout
if (diffu)
Exec = %Exec% -u
if (diffq)
Exec = %Exec% -q
if (diffr)
{
Exec = %Exec% -r
FileSelectFolder, diffdir1, c:\,,Choose Directory to diff from
if ErrorLevel <> 0
return
FileSelectFolder, diffdir2, c:\,,Choose Directory to diff to
if ErrorLevel <> 0
return
Exec = %Exec% "%diffdir1%" "%diffdir2%"
}
else
{
FileSelectFile, in1,,,"Choose From file",(*.*)
if ErrorLevel <> 0
return
FileSelectFile, in2,,,"Choose To file",(*.*)
if ErrorLevel <> 0
return
Exec = %Exec% "%in1%" "%in2%"
}
RunWait, %comspec% /c %Exec% > %TEMP%\%outname%.txt
FileRead, outtobox, %TEMP%\%outname%.txt
FileDelete, %TEMP%\%outname%.txt
Postbox := outtobox
GuiControl,, Postbox, %Postbox%
Postbox :=
}
else if (lsit)
{
Exec = %gnubins%\ls.exe
outname = lsout
if (lslg)
Exec = %Exec% -g
if (lsG)
Exec = %Exec% -G
if (lsA)
Exec = %Exec% -A
if (lsR)
Exec = %Exec% -R
FileSelectFolder, lsdir1, c:\,,Choose Directory to list
if ErrorLevel <> 0
return
RunWait, %comspec% /c %Exec% "%lsdir1%" > %TEMP%\%outname%.txt
FileRead, outtobox, %TEMP%\%outname%.txt
FileDelete, %TEMP%\%outname%.txt
Postbox := outtobox
GuiControl,,Postbox, %Postbox%
Postbox :=
}
else if (pdf2txtit)
{
Exec = %gnubins%\pdftotext.exe
if (pdf2txtlayout)
Exec = %Exec% -layout
FileSelectFile, pdftxtout,, c:\,"Choose pdf file to extract text from",(*.pdf)
if ErrorLevel <> 0
return
RunWait, %comspec% /c %Exec% "%pdftxtout%"
}
else if (pdfimagesit)
{
Exec = %gnubins%\pdfimages.exe
if (pdfimagesjpg)
Exec = %Exec% -j
FileSelectFile, pdftxtout,, c:\,"Choose pdf file to extract images from",(*.pdf)
if ErrorLevel <> 0
return
if imagerootname =
{
SplitPath, pdftxtout,,,, PdfNameNoExt,
imagerootname = %PdfNameNoExt%
}
RunWait, %comspec% /c %Exec% "%pdftxtout%" "%imagerootname%"
}
else if (pdfinfoit)
{
Exec = %gnubins%\pdfinfo.exe
outname = pdfinfoout
FileSelectFile, in1,, c:\,"Choose pdf to query",(*.pdf)
if ErrorLevel <> 0
return
RunWait, %comspec% /c %Exec% "%in1%" > %TEMP%\%outname%.txt
FileRead, outtobox, %TEMP%\%outname%.txt
FileDelete, %TEMP%\%outname%.txt
Postbox := outtobox
GuiControl, 1:, Postbox, %Postbox%
Postbox :=
}
else if (bzit)
{
Exec = %gnubins%\bzip2.exe
FileSelectFile, bzout,,,"Select file to compress with bzip2",(*.*)
if ErrorLevel <> 0
return
RunWait, %comspec% /c %Exec% "%bzout%"
}
else if (bunzit)
{
Exec = %gnubins%\bunzip2.exe
FileSelectFile, bzout,,,"Select bzip2 file to decompress",(*.bz2)
if ErrorLevel <> 0
return
RunWait, %comspec% /c %Exec% "%bzout%"
}
else if (grepit)
{
Exec = %gnubins%\grep.exe
outname = grepout
; Assign contents of grepbox to another variable
; for no particular reason.
; %grepbox% also works for the command line option.
GuiControlGet, grepsrch,, grepbox
if grepsrch =
{
MsgBox, Need something to search for.
return
}
if (grepi)
Exec = %Exec% -i
if (grepr)
{
Exec = %Exec% -r
FileSelectFolder, grepdir1, c:\,,Choose Starting Directory to grep from
if ErrorLevel <> 0
return
Exec = %Exec% %grepsrch% "%grepdir1%"
}
else
{
FileSelectFile, in1,,,"Choose file",(*.*)
if ErrorLevel <> 0
return
Exec = %Exec% %grepsrch% "%in1%"
}
RunWait, %comspec% /c %Exec% > %TEMP%\%outname%.txt
FileRead, outtobox, %TEMP%\%outname%.txt
FileDelete, %TEMP%\%outname%.txt
Postbox := outtobox
GuiControl,,Postbox, %Postbox%
Postbox :=
}
else
{
MsgBox, Nothing done
}
; remove Return to exit after pressing Ok
Return
;GuiSize:
;if ErrorLevel = 1 ; The window has been minimized. No action needed.
return
; Otherwise, the window has been resized or maximized. Resize the Edit control to match.
;NewWidth := A_GuiWidth - 10
;NewHeight := A_GuiHeight - 10
;GuiControl, Move, Postbox, W%NewWidth% H%NewHeight%
;return
; ### Mogoo ###
Openmogoo:
Gui, 1:+Disabled
Gui, 2:Show, x250 y150, MoGoo
return
Mogoostuff:
; Gui, 2:+ToolWindow +AlwaysOnTop +owner
Gui, 2:+AlwaysOnTop +owner
Gui, 2:Add, Radio, xm Section vbmp2pngit, &bmp2png
Gui, 2:Add, Radio, xs y+20 vgif2pngit, g&if2png
Gui, 2:Add, Checkbox, xs vgif2pngopt Checked, -O Optimi&ze
Gui, 2:Add, Button, xm y+20 Section, &Goomo
Gui, 2:Add, Button, xs, &Quit
Gui, 2:Add, Button, ym gBtnCancel Default, &Cancel
return
2ButtonGoomo:
Gui, 1:-Disabled
Gui, 2:Submit
if (bmp2pngit)
{
Exec = %gnubins%\bmp2png.exe
MsgBox, If output name already exits,`nbmp2png will exit will an "illegal operation".
FileSelectFile, in1,, c:\,"Choose bitmap to convert to png",(*.bmp)
if ErrorLevel <> 0
return
RunWait, %comspec% /c %Exec% "%in1%"
}
else if (gif2pngit)
{
Exec = %gnubins%\gif2png.exe
if (gif2pngopt)
Exec = %Exec% -O
FileSelectFile, in1,, c:\,"Choose gif to convert to png",(*.gif)
if ErrorLevel <> 0
return
RunWait, %comspec% /c %Exec% "%in1%"
}
else
{
MsgBox, This script developed by O
}
Return
2ButtonQuit:
Exitapp
2GuiClose:
2GuiEscape:
BtnCancel:
Gui, 1:-Disabled
Gui, 2:Cancel
return
ButtonClear:
Postbox :=
GuiControl,,Postbox, %Postbox%
Return
ButtonQuit:
Gui, Destroy
GuiClose:
GuiEscape:
ExitApp
|
_________________ Berserker |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Tue Jun 28, 2005 10:05 am Post subject: Re: gnugoo |
|
|
Looks like a great GUI front end for some high-power command line tools. Thanks for sharing it.
| olaf wrote: | | The most frustrating bug, and maybe someone has a suggestion, is that really long filenames or long directory names and filenames will cause script errors for diff, ls, and grep. When running a bin manually through a command prompt, this does not happen, and is not an issue, so I don't think it is a bug within the binaries. I also don't think the bug is with ahk. | I can't think of an explanation either. If you find out more, please post here. |
|
| Back to top |
|
 |
olaf
Joined: 20 Apr 2005 Posts: 25
|
Posted: Tue Jun 28, 2005 10:36 am Post subject: Re: gnugoo |
|
|
| Chris wrote: | | Looks like a great GUI front end for some high-power command line tools. Thanks for sharing it. |
Thanks Chris.
As a suggestion, I find it easier to copy the script to a directory where a specific tool is needed, but this still will not fix the long file/dir but thing.
olaf _________________ Berserker |
|
| Back to top |
|
 |
daonlyfreez
Joined: 16 Mar 2005 Posts: 745 Location: Berlin
|
Posted: Tue Jun 28, 2005 1:04 pm Post subject: |
|
|
Did you try converting long file names/paths to short/8.3? _________________ (sorry, homesite offline atm) |
|
| Back to top |
|
 |
olaf
Joined: 20 Apr 2005 Posts: 25
|
Posted: Tue Jun 28, 2005 3:49 pm Post subject: |
|
|
| daonlyfreez wrote: | | Did you try converting long file names/paths to short/8.3? |
Well, it only seems to happen when the name of the file and/or directory reaches roughly 20+ characters, so I don't think it's an 8.3 thing. Also, the bins work in any length, as far as I can tell, when manually using them as designed at a command prompt. Thanks for the suggestion, regardless.
I did an experiment in the root directory of a drive, and created a directory
named "1234567890123456789012345" or somewhere around there, and worked my way backwards, and the script finally started working around the 20-21st length (i don't recall exactly where). I think I had simple one character named control files in there named like "1.txt" and "2.txt" or "a.txt" and "b.txt" for testing.
olaf _________________ Berserker |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|