Page 1 of 1

Autohotkey SAC Session chooser

PostPosted: Sat Feb 02, 2013 12:36 pm
by gdougherty
Attached, please find an AutoHotkey GUI script to launch SAC with predefined sessions and automatically bring the engine live. This has been indispensable at our church.

Notes:
You'll need to download and install AutoHotkey.
http://www.autohotkey.com/

Copy and save the code below to a text file and rename the extension to .ahk

You can drop it in the Startup folder to auto-execute at windows startup.

Button display text can contain spaces. Omit the spaces and change each command section to match the button.
example: Change button "Option 1" to read "Speaking Only", change ButtonOption1 to ButtonSpeakingOnly.

Change the session file and file path to match your desired sessions.

Download SmartGUI from the AutoHotkey website if you want to easily do more extensive editing to the GUI.

A similar task without the GUI commands could be created to launch SAC and bring the engine live without user intervention on startup. The Run, sleep and controlclick commands are all that's needed.

Brett and any autohotkey guru's know a better way to ensure SAC is open and the session is loaded than using a sleep command? Seems that should be doable. The main window loads first and you can't really depend on any other specific SAC window being open either, though they wouldn't be until the session is loaded. Maybe there's a way to check and ensure a process is running and a window title contains certain text?


Code: Select all
Gui, Add, Button, x16 y40 w110 h50 +Center, Option 1
Gui, Add, Button, x146 y40 w110 h50 +Center, Option 2
Gui, Add, Button, x16 y110 w110 h50 +Center, Option 3
Gui, Add, Button, x146 y110 w110 h50 +Center, Stop SAC
Gui, Font, S16 CDefault Bold, Verdana
Gui, Add, Text, x26 y5 w220 h30 +Center, SAC Launcher
Gui, Show, h181 w277, SAC Launcher
Return

ButtonOption1:
IfWinNotExist, ahk_class SAC_MAIN
{
   Run C:\SAC\sac.exe C:\SAC\Mix\test1.mxs
   Sleep 1000
   ControlClick x25 y55, ahk_class SAC_MAIN,, right,,Pos
}
Else
{}
Return

ButtonOption2:
IfWinNotExist, ahk_class SAC_MAIN
{
   Run C:\SAC\sac.exe C:\SAC\Mix\test2.mxs
   Sleep 1000
   ControlClick x25 y55, ahk_class SAC_MAIN,, right,,Pos
}
Else
{}
Return

ButtonOption3:
IfWinNotExist, ahk_class SAC_MAIN
{
   Run C:\SAC\sac.exe C:\SAC\Mix\test3.mxs
   Sleep 1000
   ControlClick x25 y55, ahk_class SAC_MAIN,, right,,Pos
}
Else
{}
Return

ButtonStopSAC:
IfWinExist, ahk_class SAC_MAIN
{
   ControlClick x25 y55, ahk_class SAC_MAIN,, right,,Pos
   WinClose ahk_class SAC_MAIN
}
Else
{
}
Return

GuiClose:
ExitApp

Re: Autohotkey SAC Session chooser

PostPosted: Sat Feb 02, 2013 2:16 pm
by BrettBrandon
Are you having problems with it loading or just wanting to ensure there won't be any?

Brett

Re: Autohotkey SAC Session chooser

PostPosted: Sat Feb 02, 2013 5:20 pm
by gdougherty
It waits longer than it needs to before bringing the engine live because simple plugin free sessions start fast but I've had plugin heavy sessions take 2-3seconds to load. It also works fine on one system with an SSD but may not work so universally well on other systems unless it waited even longer.

Re: Autohotkey SAC Session chooser

PostPosted: Sat Feb 02, 2013 6:43 pm
by BrettBrandon
I did some checking. I can't find where you can pull the session file name from SAC to verify the session is open. You can verify that SAC_MAIN is open and active, but that does not tell you if the session file is done loading. Your sleep method for now seems the best to me but you may need to set it to 3000 or so for slower loads. I'll keep looking. Maybe someone else has an idea....

Brett

Re: Autohotkey SAC Session chooser

PostPosted: Sat Feb 02, 2013 8:07 pm
by BrettBrandon
OK George, I did some brainstorming and I think I have a solution.
I can't find any way to get the session title but what I did notice is that the "Live" button starts flashing once the session load completes. So I have it compare pixels until they don't match (session loaded) then jump to the click live.
So here's the code I have for it.

ButtonOption1:
IfWinNotExist, ahk_class SAC_MAIN
Run C:\SAC\sac.exe C:\SAC\Mix\test1.mxs
PixelGetColor, PixelColor1, 25, 55
Loop
{
PixelGetColor, PixelColor2, 25, 55
IfNotEqual, PixelColor1, %PixelColor2%
Goto, Done1
}
Done1:
WinShow, ahk_class SAC_MAIN
WinActivate, ahk_class SAC_MAIN
ControlClick x25 y55, ahk_class SAC_MAIN,, right,,Pos
Return


I have tried it with some sessions and it seems to work but I don't really have any big sessions to check very long load times.
Let me know if this works....

Brett

Re: Autohotkey SAC Session chooser

PostPosted: Sat Feb 02, 2013 8:59 pm
by gdougherty
That's ingenious. I'll give it a try tomorrow morning when I've got the system in front of me.

Re: Autohotkey SAC Session chooser

PostPosted: Sat Feb 02, 2013 10:24 pm
by BrettBrandon
I found a larger session and found about 1 out of 5 times it would not bring it live.
I made an adjustment to the code and have it all here.
Code: Select all
Gui, Font, S12 CDefault Normal,
Gui, Add, Button, x16 y40 w110 h50 +Center, Option 1
Gui, Add, Button, x146 y40 w110 h50 +Center, Option 2
Gui, Add, Button, x16 y110 w110 h50 +Center, Option 3
Gui, Add, Button, x146 y110 w110 h50 +Center, Stop SAC
Gui, Font, S16 CDefault Bold, Verdana
Gui, Add, Text, x26 y5 w220 h30 +Center, SAC Launcher
Gui, Show, h181 w277, SAC Launcher
Return



ButtonOption1:
IfWinNotExist, ahk_class SAC_MAIN
Run C:\SAC\sac.exe C:\SAC\Mix\test1.mxs
Sleep, 1000
PixelGetColor, PixelColor1, 25, 55
Loop
{
   PixelGetColor, PixelColor2, 25, 55
   IfNotEqual, PixelColor1, %PixelColor2%
   Goto, Done1
}
Done1:
WinShow, ahk_class SAC_MAIN
WinActivate, ahk_class SAC_MAIN
ControlClick x25 y55, ahk_class SAC_MAIN,, right,,Pos
Return



ButtonOption2:
IfWinNotExist, ahk_class SAC_MAIN
Run C:\SAC\sac.exe C:\SAC\Mix\test2.mxs
Sleep, 1000
PixelGetColor, PixelColor1, 25, 55
Loop
{
   PixelGetColor, PixelColor2, 25, 55
   IfNotEqual, PixelColor1, %PixelColor2%
   Goto, Done2
}
Done2:
WinShow, ahk_class SAC_MAIN
WinActivate, ahk_class SAC_MAIN
ControlClick x25 y55, ahk_class SAC_MAIN,, right,,Pos
Return


ButtonOption3:
IfWinNotExist, ahk_class SAC_MAIN
Run C:\SAC\sac.exe C:\SAC\Mix\test3.mxs
Sleep, 1000
PixelGetColor, PixelColor1, 25, 55
Loop
{
   PixelGetColor, PixelColor2, 25, 55
   IfNotEqual, PixelColor1, %PixelColor2%
   Goto, Done3
}
Done3:
WinShow, ahk_class SAC_MAIN
WinActivate, ahk_class SAC_MAIN
ControlClick x25 y55, ahk_class SAC_MAIN,, right,,Pos
Return



ButtonStopSAC:
IfWinExist, ahk_class SAC_MAIN
{
   ControlClick x25 y55, ahk_class SAC_MAIN,, right,,Pos
   WinClose ahk_class SAC_MAIN
}
Else
{
}
Return

GuiClose:
ExitApp


With the sleep added it went live every time.....

Brett