AutoHotkey Community

It is currently May 27th, 2012, 11:33 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: November 3rd, 2010, 4:51 pm 
Offline

Joined: February 19th, 2010, 6:11 pm
Posts: 150
Location: California
He's got a good point.
Hey gwarble
I dont suppose you could make it into a function so we can just do the include and yadda yadda.

So then you can explain quickly how to use it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 6th, 2010, 5:21 am 
Offline

Joined: May 23rd, 2009, 4:48 am
Posts: 365
Location: north bay, california
are we reading the same thread?

from what i can tell the first post of this thread does say that it is a stdlib compatible function, and has four (4) single-line examples, even with comments

the second post has a detailed description as to what this function accomplishes... and the third post has a detailed example made from Sean's WinTrayMin script


the function is very simple and doesn't have many options so i can't think of any other way to show and demonstrate its functionality... i would recommend just trying it, and i will of course answer any questions you may have


- gwarble

Edit: oh yeah, and the tenth post has a simple example with only one .ahk to save, which demonstrates what it does pretty well, creating an icon and an exe when run... what more do you want from me?!

Edit: (i haven't looked at this thread in months so i forgot) and i even made a Documentation page (first post) formatted as close to AHK's help file as i could... ah!!!

but really i'm just glad someone's trying it, thanks


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 6th, 2010, 10:13 am 
Offline

Joined: June 14th, 2009, 7:48 pm
Posts: 331
Hi gwarble,
Sorry . . .

I may have been too tired when I posted . . .
:oops:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 4th, 2010, 9:17 am 
Offline

Joined: May 23rd, 2009, 4:48 am
Posts: 365
Location: north bay, california
i hope you guys were able to get this working... let me know if you still need/want resolution or clarification

- gwarble


Report this post
Top
 Profile  
Reply with quote  
 Post subject: v.41
PostPosted: January 22nd, 2012, 8:24 pm 
Offline

Joined: May 23rd, 2009, 4:48 am
Posts: 365
Location: north bay, california
don't know if anyone is using this function, but i find it very useful and have made some small improvements i might as well post... main improvement if you have multiple instances of your compiled script running it will WinClose all of them with a 30 second time out, instead of just killing the first found instance and then erroring out with a failed compile

Code:
;;
;  Compile() - 0.41 - by gwarble
;    compile your script on demand, with local icons/AutoHotkey.bin
;
; Compile(Action,Name,Password)
;
;    Action   "" [Default]  -waits for the compiler to finish before returning
;             Run           -to run the compiled script and close the running script
;             NoWait        -starts compiling and continues running your script
;             Recompile     -closes the running .exe and launches the .ahk (if compiled)
;                             (useful for a self-editing compiled script)
;
;    Name     "" [Default]  -uses filename of script for exe/ico/bin filenames
;             Other         -specify a different name for the input ico/bin and output exe
;
;    Password **            -compilation password
;
;    Return   1 on success
;             0 on failure, compiler not found, already compiled, etc...
;
;    Notes    save custom icon as ScriptName.ico (in a subdir is ok) or
;             save modified AutoHotkeySC.bin as ScriptName.AHK.bin
;
Compile(Action="",Name="",Password="") {
 If A_IsCompiled   
  If Action <> Recompile   ; unless "ReCompile", function does nothing when running compiled
   Return 0
  Else
  {
   SplitPath, A_ScriptFullPath,,,,ScriptName
   Run, %ScriptName%.ahk    ; if is Recompile, will close the running exe and launch the ahk script
   Return 1      ; which should have its own auto-exeute Compile("Run")
  }
 SplitPath, A_ScriptFullPath,, ScriptDir,, ScriptName
 If Name <>
  ScriptName := Name   ; Name parameter overrides icon/exe name from Scripts name
 Icon := ExeFile := ScriptDir "\" ScriptName ".exe"
 Loop, %ScriptName%.AHK.bin, 0, 1   ; find .AHK.bin file if it exists, including subdirs
  IfExist %A_LoopFileFullPath%
  {
   Icon := CompilerBin := A_LoopFileFullPath
   Break
  }
 If CompilerBin =      ; otherwise, use a found ScriptName.ico for the compile process
  Loop, %ScriptName%.ico, 0, 1   ; including subdirs
   IfExist %A_LoopFileFullPath%   
   {
    ScriptIcon = /icon "%A_LoopFileFullPath%"
    Icon = %A_LoopFileFullPath%   ; and sets it for the run string to run the compiler later
    Break
   }
 SplitPath, A_AhkPath,, Compiler,,,  ; find compiler...
 Compiler := Compiler "\Compiler\Ahk2Exe.exe"   ; assumes compiler is in AHKPath default Compiler dir
 IfNotExist %Compiler%      ; otherwise, checks registry for AHK install dir
 {         ; poor method checks the context menu for the compile command
  RegRead, Compiler, HKCR, AutoHotkeyScript\Shell\Compile\Command ; for location of compiler
  StringReplace, Compiler, Compiler, ",,All
  StringReplace, Compiler, Compiler, % "/in %l"   ; and clean up that context menu command to the exe path
  IfNotExist %Compiler%
  {
   Loop %A_StartMenuCommon%\*.*, 0, 1   ; otherwise check the start menu for compiler's default shortcut
    If A_LoopFileName contains convert .ahk to .exe
    {
     FileGetShortcut, % A_LoopFileFullPath, Compiler
     Break
    }
   IfNotExist %Compiler%      ; otherwise assumes AHK (and compiler) is not installed
    Loop, %A_ScriptDir%\Ahk2Exe.exe, 0, 1   ; so checks the local dir for the compiler
     Compiler := %A_LoopFileFullPath%    ; including subdirs
  }
  IfNotExist %Compiler%      ; and after all that if no compiler is found, returns error (0)
   Return 0            ; compiler not found
 }

 Prev_DetectHiddenWindows := A_DetectHiddenWindows
 DetectHiddenWindows On      ; loop to WinClose all running processes before compiling
 Loop
  IfWinExist, % ExeFile,,30
   WinClose
  Else
   Break
 DetectHiddenWindows %Prev_DetectHiddenWindows%

 If (Password)           ; sets compilation password
  Password := "/pass " Password      ; untested feature

 Loop, %ScriptName%.AHK.bin, 0, 1
  IfExist %A_LoopFileFullPath%      ; if custom .bin is used, copy it in place
  {         ; after backing up the original
   SplitPath, Compiler,, CompilerDir,,,
   CompilerBin := CompilerDir "\AutoHotkeySC.bin"
   FileCopy, % CompilerBin, % CompilerDir "\AutoHotkeySC.Last.bin", 1 ; backed up original every run
   FileCopy, % CompilerBin, % CompilerDir "\AutoHotkeySC.Orig.bin", 0 ; first backup made won't be overwritten
   FileCopy, % A_LoopFileFullPath , % CompilerBin, 1
   Break
  }         ; and finally, put all those options together
 RunLine = %Compiler% /in "%A_ScriptFullPath%" /out "%ExeFile%" %ScriptIcon% %Password%
 If Action = NoWait      ; decide how to run it (first parameter)
  Run,     % RunLine, % A_ScriptDir, Hide
 Else
  RunWait, % RunLine, % A_ScriptDir, Hide
 If (CompilerBin)         ; restore the original SC.bin file if a custom one was used
  FileCopy, % CompilerDir "\AutoHotkeySC.Last.bin", % CompilerBin, 1
 If Action = Run         ; and run the compiled script if "Run" option is used (typical)
 {
  Run, % ScriptName
  ExitApp
 }
Return 1
}


and updated the first post and downloadable version

_________________
Notify() | Compile() | Instance() | LV_Group()
EitherMouse
Recommended: AHK_L (don't forget its a superset of _Basic)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 4th, 2012, 10:56 pm 
Offline

Joined: May 23rd, 2009, 4:48 am
Posts: 365
Location: north bay, california
quick update, I've finally tried the switch to AHK_L and this function appears to be working fine...

of course the .AHK.bin file will need to be rebuilt with _L's .bin

if all goes well i'll be adding support for including the compiler and having the choice between different builds if i get to it

if anyone's still using _Basic please speak up or I may break backwards compatibility (can't think of why for this function, but I probably won't be testing it)

Edit: reading up more i see that compiling is no longer handled the same way, and ahk2exe.exe is just a script, calling native functions for resources and compiling (which is now just adding the script as a resource to ahk.exe)

I think that makes this function obsolete for _L but i may rewrite to do all that natively, for no dependency on ahk2exe and for the same syntax here (ie using the .ahk as a "build and execute" shortcut for apps

_________________
Notify() | Compile() | Instance() | LV_Group()
EitherMouse
Recommended: AHK_L (don't forget its a superset of _Basic)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 15th, 2012, 2:05 pm 
Offline

Joined: June 2nd, 2011, 1:36 am
Posts: 22
Location: Norge
Thanks a lot for the script. I'm a noob at programming, so this comes in very handy. Atm I am writing a script to reconfigure the UI of Star Wars:TOR. Because of the nature of the game, any autohotkeyscript has first to be compiled and then run as administrator.

Noobish question: Do I have to write in #include compile.ahk, for the function to work in other scripts, or is there another, more logical way?


Here is the part of my script, that will reload the AHK for edit with AltGr-E, then use your function to compile it back to EXE with AltGr-R. Was fun to get it to work!

Code:
#NoEnv                 ; Makes sure AutoHotkey doesn't think blank spaces are part of your script
#SingleInstance force  ; Makes sure this script is only running one instance
SendMode Input         ; They preferred method in which you want AutoHotkey to simulate input to the computer
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#include compile.ahk

^!e::
Run, %A_ScriptDir%\swtor_ahk.ahk         ;Run swtor_ahk.ahk
Run,"C:\WINDOWS\system32\notepad.exe" "%A_ScriptDir%\swtor_ahk.ahk"   
IfWinExist SWTOR_AHK.ahk - Notepad
   {
          WinActivate
   }
ExitApp 
return


^!r::
Send {LCtrl Down}s{LCtrl Up}                   
Send {ALTDOWN}{F4}{ALTUP}
Compile("Run")
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 15th, 2012, 7:58 pm 
Offline

Joined: May 23rd, 2009, 4:48 am
Posts: 365
Location: north bay, california
Glad u could use it, and thanks for sharing your example

Works in stdlib directories without #include

_________________
Notify() | Compile() | Instance() | LV_Group()
EitherMouse
Recommended: AHK_L (don't forget its a superset of _Basic)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], MSN [Bot], nomissenrojb and 65 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