One Script to rule them all, One Script to find them,
One Script to bring them all and in the darkness bind them
NOTE: As I stopped developing Master Script, I also created a spinoff that is more stable and simple, and allows for starting ANY file or program. See "AppStarter" further down for this version.
NOTE2: Development of The Master Script is permanently abandoned, consider this a topic saved for historic purposes only. See http://www.autohotkey.com/forum/topic71902.html for a far superior app/scriptlauncher!
Master Script
Link to stable version: http://www.autohotkey.net/~sumon/Master%20Script.rar
Code: (Scroll to the bottom of the post - note that the code will contain newer updates as we go along, I'll update the .zip when I am satisfied with another "stable" version)
Hey again AHK community! I was in "creative mode" today, and got caught in this little project of mine - I created a script to let me manage all the awesome scripts I have. Instead of manually having to edit the AHK files and add hotkeys to my "Always running" script, I wanted to have a "Master Script" that can list, somehow sort, keybind and eventually autostart any scripts from my script folder. I have a vague memory there was someone who did something like this, if you found his script you can of course compare and see which you prefer.
I'll take the freedom of inserting a screenshot for easier overview:
The idea of this Master Script is simple, yet powerful. It parses its' folder for AHK scripts and lets you store data about them - A hotkey to launch them and if you want to autostart them or not. You can also run the scripts directly from this "Master Script". Might not sound so awesome, but being able to keybind Master Script to something handy gives you dozens of scripts at the tips of your finger.
How to run it:
Put the Master Script.ahk and Master Script Startup.ahk in your desired folder (that is, the folder that contains the scripts that you want to manage). Just open the Master Script.ahk to parse your scripts, and if you want to add hotkeys (or deactivate them - that is, remove them from the Master Script list and place them in a subfolder - "Inactive scripts". A simple workaround for now, but hey - My "Scripts" folder DID get cleaner, maybe you like it too!). Save and exit.
Next, run Master Script Startup.ahk. Et voilá, autostart-scripts will be started, and hotkey'd scripts will be hotkey'd. That's it!
(By the way, Master Script Startup places a .lnk of itself in your Autostart folder, so you can just install and forget this. It shouldn't be a nuisance, but if you don't want to use Master Script in the future, either edit the code or remove the Autostart .lnk manually. I might edit this somehow if it's desired - for me it's how I want it, makes the installation on new computers really easy).
If you want to see the code (else I'd recommend following the link and unzipping the contents to your script folder), here it is:
Master Script
Code:
; Script working name: Master Script
; Language: English
; Platform: Windows XP
; Author: Sumon (find me at AHK forums, www.autohotkey.com/forum)
; With help from: small_c0d3r
; Script Function: To be added: Searches "this" (%A_ScriptDir%) folder for scripts, and shows a GUI for enabling/disabling them, launching them, and adding hotkeys to launch them.
#singleinstance force
; Menu, Tray, Icon , msicon.ico, 1, 1 ---- OMG the icon was fugly
FileList = ; Initialize to be blank.
Loop, *.ahk, 0, 1
{
If (A_LoopFileDir = "Inactive Scripts")
Continue
Else
{
FileList = %FileList%%A_LoopFileName%`n ;`n
If (A_LoopFileDir = "")
FileDir = %FileDir%\`n
Else
FileDir = %FileDir%`n%A_ScriptsDir%%A_LoopFileDir%\`n
}
}
Loop, parse, FileDir, `n
{
if A_LoopField = ; Ignore the blank item at the end of the list, for Directories
{
; FileCount := A_Index-1 ; To also ignore the blank item in future "filecounts"
continue
}
Dir%A_Index% = %A_LoopField%
}
; Sort, FileList
Loop, parse, FileList, `n
{
if A_LoopField = ; Ignore the blank item at the end of the list.
{
FileCount := A_Index-1 ; To also ignore the blank item in future Filecounts
continue
}
File%A_Index% = %A_LoopField%
/*
MsgBox, 4,, File number %A_Index% is %A_LoopField%. Continue?
IfMsgBox, No
break
*/
}
IniWrite, %Filecount%, Master Script Settings.ini, Filecount, Filecount
IniRead, Filecount, Master Script Settings.ini, Filecount, Filecount, 0
Loop, %Filecount% ; Inireads all needed values
{
Iniread, Scriptname%A_Index%, Master Script Settings.ini, Scriptname, Script%A_Index%
Iniread, Autostart%A_Index%, Master Script Settings.ini, Autostart, Script%A_Index%
Iniread, Hotkey%A_Index%, Master Script Settings.ini, Hotkey, Script%A_Index%
Iniread, Winkey%A_Index%, Master Script Settings.ini, Winkey, Script%A_Index%
IniRead, ScriptDir%A_Index%, Master Script Settings.ini, Directory, Script%A_Index%, %A_ScriptDir%
; File%A_Index% := Scriptname%A_Index% <--- Commented out since there was a conflict
}
CreateGUI:
Gui -Maximizebox
Gui, Add, Text,, ... parsed your folder(s) for %Filecount% files...
Gui, Add, Button, gSubmit, Save && Update
; Gui, Add, Button, xp+95 yp gMasterstartup, Master Startup
Gui, Add, Button, xp+90 yp gReset, Reset
Gui, Add, Button, xp+50 yp w25 gHelp, ?
Gui, Add, Button, xp+30 yp gSettings, Settings
Gui, Add, Button, xp+50 yp gExit, Exit
Gui, Add, Text, y+15 xp-200, Run script | Autostart | Hotkey | +Win key? | Hide
Gui, Add, Tab, w300 h960 Buttons, 1-15|16-30|31-45|46-60|61-75
Gui, Tab, 1
Loop, %Filecount%
{
FileText := File%A_Index%
CurrentScriptDir := ScriptDir%A_Index%
PreviousScriptDir := "Null"
If (CurrentScriptDir ! PreviousScriptDir)
MsgBox New directory is %CurrentScriptDir%
;Gui, Add, Text, x20 yp+35, %CurrentScriptDir%
PreviousScriptDir := ScriptDir%A_Index%
If (A_Index = 16)
Gosub, NewTab16
If (A_Index = 31)
Gosub, NewTab31
If (A_Index = 46)
Gosub, NewTab46
If (A_Index = 61)
Gosub, NewTab61
Gui, Add, GroupBox, x20 yp+35 w350, %FileText%
GUI, Add, Button, Section xp+10 yp+20 h20 r1 gLaunchFileselect, %A_Index%
LaunchindexN = Launchindex%A_Index% ; ?
n := Autostart%A_Index%
Gui, Add, Checkbox, xp+70 yp+5 r1 vAutostartN%A_Index% checked%n%
n := Hotkey%A_Index%
Gui, Add, Hotkey, xp+50 yp-5 w70 vHotkeyN%A_Index%, %n%
n := Winkey%A_Index%
Gui, Add, Checkbox, xp+75 yp+5 r1 vWinkeyN%A_Index% checked%n%
Gui, Add, Checkbox, xp+75 yp vDeactivateN%A_Index%
LastScriptListed = %A_Index%
}
Gui, Color, EFFAE8
Gui, Show
return
NewTab16:
Gui, Tab, 2
Gui, Add, Text, x0 y100,
return
NewTab31:
Gui, Tab, 3
Gui, Add, Text, x0 y100,
return
NewTab46:
Gui, Tab, 4
Gui, Add, Text, x0 y100,
return
NewTab61:
Gui, Tab, 5
Gui, Add, Text, x0 y100,
return
reset:
Gui, Destroy
Gosub, CreateGUI
return
Submit:
Gui, Submit, nohide
Loop, %FileCount%
{
ScriptnameIni := File%A_Index%
IniWrite, %ScriptnameIni%, Master Script Settings.ini, Scriptname, Script%A_Index%
AutostartIni := AutostartN%A_Index%
DirIni := Dir%A_Index%
IniWrite, %DirIni%, Master Script Settings.ini, Directory, Script%A_Index% ; This row and above was added by small_c0d3r to allow for recursing foldersearch
IniWrite, %AutostartINI%, Master Script Settings.ini, Autostart, Script%A_Index%
HotkeyINI := HotkeyN%A_Index%
IniWrite, %HotkeyINI%, Master Script Settings.ini, Hotkey, Script%A_Index%
WinkeyINI := WinkeyN%A_Index%
IniWrite, %WinkeyINI%, Master Script Settings.ini, Winkey, Script%A_Index%
DeactivateINI := DeactivateN%A_Index% ; Yes, I know the this INI value won't be used, but can be good to have if someone wants to change the script
IniWrite, %DeactivateIni%, Master Script Settings.ini, Deactivate, Script%A_Index%
Filemovetext := File%A_Index%
FileCreateDir, Inactive Scripts
If (DeactivateN%A_Index% = 1)
FileMove, %DirIni%\%Filemovetext%, %A_ScriptDir%\Inactive Scripts\
}
reload
return
Settings:
Iniread, Extrafolder1, Master Script Settings, ExtraFolder, 1, _ _ _
Gui, 2:+Owner1 +Resize
Gui, 2: Add, Text,, SETTINGS ARE NOT YET FUNCTIONING - THEY ARE TO BE IMPLEMENTED SOON (tm)
Gui, 2:Add, Text,, Folders to be searched...`nDefault: %A_ScriptDir%`n1: %ExtraFolder1%`n2: %ExtraFolder2%`n3: %Extrafolder3%
Gui, 2: Add, Button, gAddFolder, Add folder...
Gui, 2:Add, Button, gSubmit2, Save settings
Gui, 2:Show, w400 h300, Settings
return
AddFolder:
FileSelectFolder, ExtraFolder1, *%A_ScriptDir%,, Select a folder to include in future searches
IniWrite, %Extrafolder1%, Master Script Settings, ExtraFolder, 1
return
Submit2:
Gui, 2:Submit
Gui, 2:Destroy
return
Exit:
ExitApp
return
reload:
Reload
return
Masterstartup:
MsgBox FAIL
return
Help:
MsgBox Run script - Runs the chosen script `nAutostart - The chosen script will always start when you start your computer `nHotkey & Win key - Assign a hotkey to launch the selected script, if you want to combine it with the Windows key: Also tick the "Win key?" button (remember to deactivate it when it's not used) `nDeactivate - Moves the designated script to a subfolder called "Inactive scripts", so it will not appear in this list
return
Launch:
SoundPlay, *64
Run, %FiletoLaunch%
return
; THE FOLLOWING "LaunchFileSelect subroutine considers which button was pressed (thanks to small_c0d3r)
LaunchFileSelect:
Selected_File:= File%A_GuiControl%
Selected_File_Dir:= Dir%A_GuiControl%
FiletoLaunch = %A_ScriptDir%%Selected_File_Dir%%Selected_File%
;Msgbox, %FiletoLaunch%
Gosub, Launch
Return
Master Script Startup
Code:
; Script working name: Master Script Startup
; Goes hand in hand with: Master Script.ahk, and Master Script Settings.ini
; Language: English
; Platform: Windows 7
; Version author: Sumon (find me at AHK forums, www.autohotkey.com/forum)
; Script Function: Autostarts itself (if commanded to) and other scripts you wish to autostart. Also keeps hotkeys available for desired scripts.
#singleinstance force
#NoEnv
SetBatchLines, -1
SplashTextOn, 400, 70, Master Script, Master Script has been launched :)
Sleep 3000
SplashTextOff
IfNotExist %A_Startup%\Master Script Startup.lnk ; Adds Master Script Startup to Autostart
FileCreateShortcut , %A_ScriptDir%\Master Script Startup.ahk, %A_Startup%\Master Script Startup.lnk
IniRead, Filecount, Master Script Settings.ini, Filecount, Filecount, 0
Loop, %Filecount% ; Inireads all needed values
{
Iniread, Scriptname%A_Index%, Master Script Settings.ini, Scriptname, Script%A_Index%
Iniread, Autostart%A_Index%, Master Script Settings.ini, Autostart, Script%A_Index%
Iniread, Hotkey%A_Index%, Master Script Settings.ini, Hotkey, Script%A_Index%
Iniread, Winkey%A_Index%, Master Script Settings.ini, Winkey, Script%A_Index%
Iniread, Dir%A_Index%, Master Script Settings.ini, Directory, Script%A_Index% ; Added on behalf of Small_c0d3r
File%A_Index% := Scriptname%A_Index%
}
Loop, %Filecount% ; Starts desired scripts on computer startup
{
RunScriptName := Dir%A_index% "\" Scriptname%A_Index% ; To allow running of scripts in recursed folders (/Small_c0d3r)
If (Autostart%A_Index% = 1)
Run, %RunScriptName%
}
HotkeyCount = 0
Loop, %Filecount% ; Assigns desired hotkeys
{
if (Hotkey%A_Index% = "")
continue
WK =
if (Winkey%A_Index% = 1)
WK = #
HotkeyCount := (HotkeyCount + 1)
Hotkeys := Hotkey%A_Index%
Hotkey, %WK%%Hotkeys%, LaunchN%A_Index%
}
return
Launch:
MSS := Master Script Startup
StringTrimRight, FTL, Filetolaunch, 4 ; To remove the .ahk, for some reason I got "Unallowed variable" due to the dot (.)
If (FTL = MSS)
MsgBox Error! Reload immediately!
Run, %FiletoLaunch%,,, PIDLaunched ; FiletoLaunch comes from the sub(s) below
Process, Wait, %PidLaunched%, 0.5
Process, Exist, %PidLaunched%
If (Errorlevel > 0){
SoundPlay, *64
SplashtextOn, 200, 50,, Launched %Filetolaunch%
Sleep 2000
SplashtextOff
}else{
MsgBox Error
}
return
; Alright, here we go again: The rest is basically the same!
LaunchN1:
FiletoLaunch = %File1%
Gosub, Launch
return
LaunchN2:
FiletoLaunch = %File2%
Gosub, Launch
return
LaunchN3:
FiletoLaunch = %File3%
Gosub, Launch
return
LaunchN4:
FiletoLaunch = %File4%
Gosub, Launch
return
LaunchN5:
FiletoLaunch = %File5%
Gosub, Launch
return
LaunchN6:
FiletoLaunch = %File6%
Gosub, Launch
return
LaunchN7:
FiletoLaunch = %File7%
Gosub, Launch
return
LaunchN8:
FiletoLaunch = %File8%
Gosub, Launch
return
LaunchN9:
FiletoLaunch = %File9%
Gosub, Launch
return
LaunchN10:
FiletoLaunch = %File10%
Gosub, Launch
return
LaunchN11:
FiletoLaunch = %File11%
Gosub, Launch
return
LaunchN12:
FiletoLaunch = %File12%
Gosub, Launch
return
LaunchN13:
FiletoLaunch = %File13%
Gosub, Launch
return
LaunchN14:
FiletoLaunch = %File14%
Gosub, Launch
return
LaunchN15:
FiletoLaunch = %File15%
Gosub, Launch
return
LaunchN16:
FiletoLaunch = %File16%
Gosub, Launch
return
LaunchN17:
FiletoLaunch = %File17%
Gosub, Launch
return
LaunchN18:
FiletoLaunch = %File18%
Gosub, Launch
return
LaunchN19:
FiletoLaunch = %File19%
Gosub, Launch
return
LaunchN20:
FiletoLaunch = %File20%
Gosub, Launch
return
LaunchN21:
FiletoLaunch = %File21%
Gosub, Launch
return
LaunchN22:
FiletoLaunch = %File22%
Gosub, Launch
return
LaunchN23:
FiletoLaunch = %File23%
Gosub, Launch
return
LaunchN24:
FiletoLaunch = %File24%
Gosub, Launch
return
LaunchN25:
FiletoLaunch = %File25%
Gosub, Launch
return
LaunchN26:
FiletoLaunch = %File26%
Gosub, Launch
return
LaunchN27:
FiletoLaunch = %File27%
Gosub, Launch
return
LaunchN28:
FiletoLaunch = %File28%
Gosub, Launch
return
LaunchN29:
FiletoLaunch = %File29%
Gosub, Launch
return
LaunchN30:
FiletoLaunch = %File30%
Gosub, Launch
return
LaunchN31:
FiletoLaunch = %File31%
Gosub, Launch
return
LaunchN32:
FiletoLaunch = %File32%
Gosub, Launch
return
LaunchN33:
FiletoLaunch = %File33%
Gosub, Launch
return
LaunchN34:
FiletoLaunch = %File34%
Gosub, Launch
return
LaunchN35:
FiletoLaunch = %File35%
Gosub, Launch
return
LaunchN36:
FiletoLaunch = %File36%
Gosub, Launch
return
LaunchN37:
FiletoLaunch = %File37%
Gosub, Launch
return
LaunchN38:
FiletoLaunch = %File38%
Gosub, Launch
return
LaunchN39:
FiletoLaunch = %File39%
Gosub, Launch
return
LaunchN40:
FiletoLaunch = %File40%
Gosub, Launch
return
LaunchN41:
FiletoLaunch = %File41%
Gosub, Launch
return
LaunchN42:
FiletoLaunch = %Fil42%
Gosub, Launch
return
LaunchN43:
FiletoLaunch = %File43%
Gosub, Launch
return
Link: http://www.autohotkey.net/~sumon/Master%20Script.rarImportant: The Script(s) must be placed in the folder that you want it to scan. I plan on eventually implementing a function to select additional parsing foldersPlease comment, especially if you try it out. Any amount of feedback is appreciated.
Regards,
sumon
Known "bugs":
- The GUI can not be scrolled, so if you have more than ~18 scripts they won't all appear. If so, try out the "Deactivate", Save & Exit and repeat. (There used to be a reload button, but euhm, removed it).
- There's a limit to around 42 scripts maximum supported, although that is a secondary concern now - however it adds bulk to the code, that I do not want there. Any advice?
- Do NOT set "The Master Script Startup.ahk" to autostart, as that'll cause it to loop. I've been trying
Code:
If (%FiletoLaunch% = %MSS%){ ; You don't wanna selfstart the script, as that'd loop
MsgBox OMG ERROR!
}else{
Run, %FiletoLaunch% ; FiletoLaunch comes from the sub(s) below
}
to no avail.
AppStarterFor a more simple (read: user-friendly), all-programs alternative, I developed "AppStarter". This will let people start any file or program, and decide for themself which programs to include. It has a simple File-Select option, and lets your store and hotkey up to 9 applications (for now). This version is stable. If you want an .exe (includes icons and #includes), you can
DOWNLOAD IT HERE.

AppStarter.ahk
Code:
;
; AutoHotkey Version: 1.x
; Language: English
; Platform: Win9x/NT
; Author: A.N.Other <myemail@nowhere.com>
;
; Script Function:
; Template script (you can customize this template by editing "ShellNew\Template.ahk" in your Windows folder)
;
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; ----
#Include IniLib.ahk
#SingleInstance, Force
#Persistent
IfExist, winpng.png
FileInstall, winpng.png, winpng.png
IfNotExist, AppStarterSettings.ini
GoSub, CreateStandardIni
initializeini()
loadini() ; section_keyname
IfExist, AppStarterIcon.ico
Menu, Tray, Icon, AppStarterIcon.ico
Menu, Tray, Tip, AppStarter
Menu, Tray, NoStandard
Menu, Tray, Add, (*) Settings, Settings
Menu, Tray, Add, (?) Help, Help
Menu, Tray, Add, (X) Exit, ExitHotkey
OnExit, ExitHotkey
Gosub, Updatehotkeys
#Include SplashMe.ahk
return
Settings:
GuiCreate:
loadini()
Gui, Add, Text, x10, Application
IfExist, winpng.png
Gui, Add, Pic, x270 yp w16 h16, winpng.png
Gui, Add, Text, x310 yp, Hotkey
Loop, 9
{
Check:=App_App%A_Index%
IfNotExist, %Check%
{
Gui, Add, Button, gAddApp x10 vApp_App%A_Index%, [ Add app %A_Index% ]
Continue
}
StringGetPos, Position, Check, \, R
StringLen, Length, Check
StringRight, Display, App_App%A_Index%, % (Length - Position - 1) ; Shortens the string for displaying
Gui, Add, Button, gLaunchApp x10 vApp_App%A_Index%, %Display%
WK:=Winkey_App%A_Index%
Gui, Add, Checkbox, vWinkey_App%A_Index% yp x270 Checked%WK%
HK:=Hotkey_App%A_Index%
Gui, Add, Hotkey, vHotkey_App%A_Index% yp x310 w80, %HK%
}
Gui, Add, Button, gSubmit x150 yp+40, Save && close
Gui, Add, Button, gHelp x230 yp, ?
Gui, Add, Button, gGuiClose x250 yp, Close
Gui, Show, W400 H350, AppStarter Settings
Sleep 2000
SplashTextOff
return
AddApp:
StringRight, Display, A_GuiControl, 1
FileSelectFile, %A_GuiControl%, S, %A_ScriptDir%, Select the application you want to add as App #%Display%
if (Errorlevel = 1)
return
saveini()
SplashOn("App was added")
SplashOff()
Gui, Destroy
Gosub, GuiCreate
return
Submit:
Gui, Submit
saveini()
SplashOn("Settings saved")
SplashOff()
Gui, Destroy
Gosub, UpdateHotkeys
return
UpdateHotkeys:
; Update Hotkeys:
Loop, 9
{
Check:=App_App%A_Index%
IfNotExist, %Check%
{
Continue
}
w =
If (Winkey_App%A_Index% = 1)
w = #
HK:=Hotkey_App%A_index%
Hotkey, ~%w%%HK%, LaunchApp%A_Index%, Off
Hotkey, ~%w%%HK%, LaunchApp%A_Index%, On
}
return
GuiClose:
Gui, Destroy
Gosub, UpdateHotkeys
return
Help:
MsgBox Version: 0.9`nAuthor & (C): Simon Strålberg (simon.stralberg@gmail.com)`n`nAppStarter is intended to give an easy way to keybind and start your favorite applications. To add an application, simply press "Add application", navigate to the app, and select it. To add a hotkey, select the hotkey field, and press a hotkey (may include modifiers: shift/alt/ctrl). If you want to include the [Windows key], simply tick that box. REMEMBER: Do not add hotkeys that conflict with existing ones. The hotkeys will both work, eventually triggering two actions if you are not careful. Please select hotkeys with care. Recommended (and by default unused) hotkeys include [Win] combined with Q, W, A, Z, V, G, Y. `n`nIf you find this or any of my other software/apps useful, do not hesitate to send me an email at <simon.stralberg@gmail.com>.`n`nHave fun, and feel free to share this application with friends!
Return
CreateStandardINI:
FileAppend
, [App]`nApp1=`nApp2=`nApp3=`nApp4=`nApp5=`nApp6=`nApp7=`nApp8=`nApp9=`n[Hotkey]`nApp1=`nApp2=`nApp3=`nApp4=`nApp5=`nApp6=`nApp7=`nApp8=`nApp9=`n[Winkey]`nApp1=0`nApp2=0`nApp3=0`nApp4=0`nApp5=0`nApp6=0`nApp7=0`nApp8=0`nApp9=0
, AppStarterSettings.ini
return
LaunchApp:
; SoundPlay, *64
ToRun:=%A_GuiControl%
Run, %ToRun%
return
LaunchApp1:
Run, % App_App1
return
LaunchApp2:
Run, % App_App2
return
LaunchApp3:
Run, % App_App3
return
LaunchApp4:
Run, % App_App4
return
LaunchApp5:
Run, % App_App5
return
LaunchApp6:
Run, % App_App6
return
LaunchApp7:
Run, % App_App7
return
LaunchApp8:
Run, % App_App8
return
LaunchApp9:
Run, % App_App9
return
ExitHotkey:
; saveini()
ExitApp
NOTE: Requires IniLib.ahk & SplashMe.ahk
IniLib.ahk
Code:
; AUTHORSHIP for IniLib.ahk, see http://www.autohotkey.com/forum/topic21346.html (Note: It was called something else then, and is configured to work with AppStarter)
initializeini(inifile = "AppStarterSettings.ini"){
global
local key,temp
inisections:=0
loop,read,%inifile%
{
if regexmatch(A_Loopreadline,"\[(.*)?]")
{
inisections+= 1
section%inisections%:=regexreplace(A_loopreadline,"(\[)(.*)?(])","$2")
section%inisections%_keys:=0
}
else if regexmatch(A_LoopReadLine,"(\w+)=(.*)")
{
section%inisections%_keys+= 1
key:=section%inisections%_keys
section%inisections%_key%key%:=regexreplace(A_LoopReadLine,"(\w+)=(.*)","$1")
}
}
}
loadini(inifile = "AppStarterSettings.ini"){
global
local sec,var
loop,%inisections%
{
sec:=A_index
loop,% section%a_index%_keys
{
var:=section%sec% "_" section%sec%_key%A_index%,
Stringreplace,var,var,%a_space%,,All
iniread,%var%,%inifile%,% section%sec%,% section%sec%_key%A_index%
}
}
}
saveini(inifile = "AppStarterSettings.ini"){
global
local sec,var
loop,%inisections%
{
sec:=A_index
loop,% section%a_index%_keys
{
var:=section%sec% "_" section%sec%_key%A_index%
Stringreplace,var,var,%a_space%,,All
var:=%var%
iniwrite,%var%,%inifile%,% section%sec%,% section%sec%_key%A_index%
}
}
}
SplashMe.ahk
Code:
;-- v1.0
; AUTHORSHIP: see http://www.autohotkey.com/forum/viewtopic.php?t=18040
;-- Important: Because this code includes a subroutine, you should
; insert/include it AFTER the Auto-Execute section of a script.
;
;*******************
;* *
;* Splash On *
;* *
;*******************
;
; Description
; ===========
; This function generates a borderless text Splash window and is used in
; conjunction with the SplashOff, PreserveSplashWindow, and SplashOff_Timer
; functions/subroutines.
;
;
;
; Parameters
; ==========
;
; Name Description
; ---- -----------
; p_MainText Main text. [Optional] The default is null.
;
; p_SubText Sub text. [Optional] The default is null.
;
; p_MinimumSplashTime Minimum time (in seconds) the splash window is
; to be displayed. [Optional] The default is
; 0.85 seconds.
;
; If p_MinimumSplashTime contains a negative value
; (Ex: -3), this function will automatically call
; the SplashOff function using the absolute value
; value of this parameter as the minimum splash
; time. This feature is useful when you know
; exactly how long you want the splash window to
; display. It also removes the need for a
; separate call to the SplashOff function.
;
; p_Font Font Name. [Optional] The default is null (the
; system default font is used).
;
; This font is used for both the MainText (top
; line(s)) and SubText (bottom line(s)).
;
;
; p_Options See the "Splash Options" section for more
; information.
;
;
;
; Global Variables
; ================
;
; Name Description
; ---- -----------
; $Splash_StartTime This variable contains the time (A_TickCount)
; that the splash window was created.
;
; $Splash_MinimumTime This variable contains minimum time
; (developer-defined or default) that the splash
; window should be displayed.
;
;
;
; Splash Options
; ==============
; The p_Options parameter is used to set any SplashImage options that are not
; set by default. If more than one option is defined, separate each option by
; a space. For example:
;
; "CWBlack CTYellow"
;
; For a complete list of SplashImage options, see the AutoHotkey
; documentation (keyword: SplashImage).
;
;
; The following SplashImage options are automatically included by default:
;
; Name Description
; ---- -----------
; b2 No title bar, dialog style border
;
; W{Function determined} Splash window width. The size doesn't include
; border.
;
;
; If not explicitly defined, the following SplashImage options/values are
; included:
;
; Name Description/Value
; ---- -----------------
; FM10 Font size for MainText - 10
; FS12 Font size for SubText - 12
; WM600 Font weight for MainText - 600 (Bold)
; WS400 Font weight for SubText - 400 (Normal)
;
;
; In addition to the standard X/Y options, the following options are
; available to position the Splash window on the screen:
;
; Name Description/Value
; ---- -----------------
; XL or XLeft Left side of the screen. Not necessarily the
; same as X0.
;
; XM or XMiddle Horizontally centered on the screen. This is
; SplashImage default.
;
; XR or XRight Right side of the screen.
;
; YT or YTop Top of the screen. Not necessarily the same as
; Y0.
;
; YM or YMiddle Vertically centered on the screen. This is
; SplashImage default.
;
; YB or YBottom Bottom of the screen.
;
;
; The preceding X/Y options are calculated based on the work area for the
; primary monitor. The work area excludes the taskbar and other registered
; desktop toolbars.
;
;
;
; Calls To Other Functions
; ========================
; SplashOff
;
;
;
; Calls To Subroutines
; ====================
; SplashOff_Timer
;
;
;
; Programming Notes
; =================
; o This function creates a temporary GUI window to ascertain the width of
; the SplashImage window. The function uses the first GUI window that is
; available in the 71 to 99 range. If an available window cannot be found,
; an error message is displayed.
;
; o So as not to interfere with any other SplashImage windows, an
; arbitrarily selected SplashImage window number (8) is used. Change if
; needed. See the AutoHotkey documentation (keyword: SplashImage) for
; more information.
;
;
;-------------------------------------------------------------------------------
SplashOn(p_MainText=""
,p_SubText=""
,p_MinimumSplashTime=""
,p_Font=""
,p_Options="")
{
global $Splash_StartTime, $Splash_MinimumTime
;[==============]
;[ Initialize ]
;[==============]
l_DetectHiddenWindows:=A_DetectHiddenWindows
DetectHiddenWindows On
l_MainTextFontSize=10
l_MainTextFontWeight=600
l_SubTextFontSize=12
l_SubTextFontWeight=400
;[==============]
;[ Parameters ]
;[==============]
;-- p_MinimumSplashTime
if p_MinimumSplashTime is not Number
p_MinimumSplashTime=0
;-- p_Font
p_Font=%p_Font% ;-- AutoTrim
;[=======================]
;[ Extract font values ]
;[ from p_Options ]
;[=======================]
loop parse,p_Options,%A_Space%
{
if A_LoopField is Space
continue
;-- MainText options
if instr(A_LoopField,"FM")=1
if SubStr(A_LoopField,3) is Number
StringTrimLeft l_MainTextFontSize,A_LoopField,2
if instr(A_LoopField,"WM")=1
if SubStr(A_LoopField,3) is Number
StringTrimLeft l_MainTextFontWeight,A_LoopField,2
;-- SubText options
if instr(A_LoopField,"FS")=1
if SubStr(A_LoopField,3) is Number
StringTrimLeft l_SubTextFontSize,A_LoopField,2
if instr(A_LoopField,"WS")=1
if SubStr(A_LoopField,3) is Number
StringTrimLeft l_SubTextFontWeight,A_LoopField,2
}
;[=============]
;[ p_Options ]
;[=============]
p_Options=%p_Options% ;-- AutoTrim
p_Options:="b2 " . p_Options
;-- If not explicitly defined, load font size just in case defaults don't
; match system default
;
if instr(p_Options," FM")=0
p_Options:=p_Options . " FM" . l_MainTextFontSize
if instr(p_Options," FS")=0
p_Options:=p_Options . " FS" . l_SubTextFontSize
;-- Update/Simplify X/Y options
StringReplace p_Options,p_Options,%A_Space%XLeft,%A_Space%XL,All
StringReplace p_Options,p_Options,%A_Space%XMiddle,,All
StringReplace p_Options,p_Options,%A_Space%XM,,All
StringReplace p_Options,p_Options,%A_Space%XRight,%A_Space%XR,All
StringReplace p_Options,p_Options,%A_Space%YTop,%A_Space%YT,All
StringReplace p_Options,p_Options,%A_Space%YMiddle,,All
StringReplace p_Options,p_Options,%A_Space%YM,,All
StringReplace p_Options,p_Options,%A_Space%YBottom,%A_Space%YB,All
;[=====================]
;[ Preliminary stuff ]
;[=====================]
;-- 1st run?
if $Splash_MinimumTime is Space
{
$Splash_MinimumTime=850 ;-- Default in milliseconds. Adjust if desired
$Splash_StartTime=0
}
;-- Turn off the SplashOff timer
SetTimer SplashOff_Timer,off
;-- Minimum splash time defined?
if p_MinimumSplashTime
{
$Splash_MinimumTime:=p_MinimumSplashTime*1000
$Splash_StartTime=0
}
;-- Reset start time?
if not $Splash_StartTime
$Splash_StartTime:=A_TickCount
;[=========================]
;[ Find available window ]
;[ (Starting with 71) ]
;[=========================]
l_GUI=71
loop
{
;-- Window available?
gui %l_GUI%:+LastFoundExist
IfWinNotExist
break
;-- Nothing available?
if l_GUI=99
{
msgbox,262160,SplashOn Error,
(ltrim
Unable to create SplashOn temporary GUI. %A_Space%
GUI windows 71 to 99 are already in use.
)
return
}
;-- Increment window
l_GUI++
}
;[==========================]
;[ Determine splash width ]
;[==========================]
;-- Build temporary window to determine maximum width
gui %l_GUI%:Margin,0,0
gui %l_GUI%:Font,s%l_MainTextFontSize% w%l_MainTextFontWeight%,%p_Font%
gui %l_GUI%:Add,Text,,%p_MainText%
gui %l_GUI%:Font,s%l_SubTextFontSize% w%l_SubTextFontWeigth%
gui %l_GUI%:Add,Text,,%p_SubText%
gui %l_GUI%:Show,Hide ;-- Render but don't show
;-- How wide is it?
gui %l_GUI%:+LastFound
WinGetPos ,,,l_SplashImageWidth,,% "ahk_id " . WinExist()
gui %l_GUI%:Destroy
;-- Add some breathing room
l_SplashImageWidth:=l_SplashImageWidth+60
;-- Too wide?
l_MaxSplashImageWidth:=round(A_ScreenWidth*0.95)
if (l_SplashImageWidth>l_MaxSplashImageWidth)
l_SplashImageWidth:=l_MaxSplashImageWidth
;[==============]
;[ Splash it! ]
;[==============]
l_BreakLoop:=false
loop 2
{
;-- Create working copy of p_Options
l_Options:=p_Options
;-- Function-specific X/Y options?
if (instr(p_Options,A_Space . "XL")
or instr(p_Options,A_Space . "XR")
or instr(p_Options,A_Space . "YT")
or instr(p_Options,A_Space . "YB"))
{
StringReplace l_Options,l_Options,%A_Space%XL,,All
StringReplace l_Options,l_Options,%A_Space%XR,,All
StringReplace l_Options,l_Options,%A_Space%YT,,All
StringReplace l_Options,l_Options,%A_Space%YB,,All
l_Options:=l_Options . " Hide"
}
else
l_BreakLoop:=true
;-- Splash using working copy of p_Options
SplashImage 8:,W%l_SplashImageWidth% %l_Options%
,%p_SubText%
,%p_MainText%
,SplashOnWindow
,%p_Font%
;-- Are we done yet?
if l_BreakLoop
break
;-- Collect splash window width and height
WinGetPos ,,,l_SplashWindowWidth,l_SplashWindowHeight,SplashOnWindow
;-- Collect work area dimensions for primary monitor
SysGet l_MonitorWorkArea,MonitorWorkArea
;-- Update X/Y positions
StringReplace p_Options
,p_Options
,%A_Space%XL
,% " X" . l_MonitorWorkAreaLeft
,All
StringReplace p_Options
,p_Options
,%A_Space%XR
,% " X" . l_MonitorWorkAreaRight-l_SplashWindowWidth
,All
StringReplace p_Options
,p_Options
,%A_Space%YT
,% " Y" . l_MonitorWorkAreaTop
,All
StringReplace p_Options
,p_Options
,%A_Space%YB
,% " Y" . l_MonitorWorkAreaBottom-l_SplashWindowHeight
,All
}
;-- Minor delay to give the window a chance to render
sleep 1
;[===================]
;[ Auto SplashOff? ]
;[===================]
if $Splash_MinimumTime<0
{
$Splash_MinimumTime:=abs($Splash_MinimumTime)
SplashOff()
}
;[================]
;[ Housekeeping ]
;[================]
DetectHiddenWindows %l_DetectHiddenWindows%
;-- Return to sender
return
}
;********************
;* *
;* Splash Off *
;* *
;********************
;
;
; Description
; ===========
; This function performs one of the following tasks:
;
; 1) If PreserveSplashWindow is TRUE (explicitly or by default), turn off
; the SplashOff timer. Do nothing else.
;
; 2) If the minimum splash time has elapsed, turn off (destroy) the splash
; window created by the SplashOn function.
;
; 3) If the minimum splash time has NOT elapsed, set a timer to turn off
; (destroy) the splash window created by the SplashOn function.
;
;
;
; Parameters
; ==========
;
; Name Description
; ---- -----------
; p_PreserveSplashWindow Preserve Splash Window. [Boolean, Optional]
; The default is FALSE or the value it was set to
; last.
;
;
;
; Calls To Other Functions
; ========================
; PreserveSplashWindow
;
;
;
; Calls To Subroutines
; ====================
; SplashOff_Timer
;
;
;-------------------------------------------------------------------------------
SplashOff(p_PreserveSplashWindow="")
{
global $Splash_MinimumTime, $Splash_StartTime
;-- Turn off SplashOff timer
SetTimer SplashOff_Timer,off
;-- Preserve splash?
if PreserveSplashWindow(p_PreserveSplashWindow)
return
;-- Compute elapsed time. Set timer if necessary
l_SplashTimeElapsed:=A_TickCount-$Splash_StartTime
if (l_SplashTimeElapsed<$Splash_MinimumTime)
{
l_SplashOffTimer:=$Splash_MinimumTime-l_SplashTimeElapsed
SetTimer SplashOff_Timer,%l_SplashOffTimer%
}
else
;-- Destroy splash window
SplashImage 8:Off
;-- Reset to defaults
$Splash_MinimumTime=1350 ;-- Default in milliseconds. Adjust if desired
$Splash_StartTime=0
;-- Return to sender
return
}
;**************************
;* *
;* Splash Off Timer *
;* *
;**************************
SplashOff_Timer:
SetTimer SplashOff_Timer,Off
SplashImage 8:Off
return
;********************************
;* *
;* Preserve Splash Window *
;* *
;********************************
;
;
; Description
; ===========
; This function sets and/or returns the current boolean value of
; s_PreserveSplashWindow.
;
; This function is called independently to set s_PreserveSplashWindow and is
; used by the SplashOff function to determine if the splash window should be
; preserved or not.
;
;
;
; Parameters
; ==========
;
; Name Description
; ---- -----------
; p_PreserveSplashWindow Determines whether the splash window is
; preserved or not. [Optional] The default is
; FALSE or whatever it was set to last.
;
; Set to TRUE to preserve the splash window. Set
; to FALSE to no longer preserve the splash
; window.
;
;
; Calls To Other Functions
; ========================
; (None)
;
;
;-------------------------------------------------------------------------------
PreserveSplashWindow(p_PreserveSplashWindow="")
{
static s_PreserveSplashWindow
;-- Parameter?
if p_PreserveSplashWindow is not Space
s_PreserveSplashWindow:=p_PreserveSplashWindow
;-- Return to sender
if s_PreserveSplashWindow
return true
else
return false
}