Skip to content

Instantly share code, notes, and snippets.

@TheFrostlixen
Last active March 28, 2019 04:17
Show Gist options
  • Save TheFrostlixen/6ba11b170416c66200532da95fbdc835 to your computer and use it in GitHub Desktop.
Save TheFrostlixen/6ba11b170416c66200532da95fbdc835 to your computer and use it in GitHub Desktop.
My Windows configuration -- Rainmeter & AutoHotKey scripts

Windows Workspace Configuration

Rainmeter

Installed skins:

My setup:

AutoHotKey

AutoHotKey allows you to create configurable global or application-specific hotkeys. My hotkeys are all contained within this file, and are all fairly simple. Also included in this gist is a script I wrote to restart a service on my computer, with optional preconfigured parameters passed in to the service.

# Set SQL Server instance name
$sqlName= "localhost\SQLEXPRESS"
# Set the databse name which you want to backup
$dbname= "HamiltonXRP2"
# Set the backup file path
$backupPath= "C:\bin\HamiltonXRP_DB.bak"
#Load the required assemlies SMO and SmoExtended.
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoExtended") | Out-Null
# Connect SQL Server.
$sqlServer = New-Object ('Microsoft.SqlServer.Management.Smo.Server') $sqlName
# Create SMO Backup object instance with the Microsoft.SqlServer.Management.Smo.Backup
$dbBackup = new-object ("Microsoft.SqlServer.Management.Smo.Backup")
$dbBackup.Database = $dbname
# Add the backup file to the Devices
$dbBackup.Devices.AddDevice($backupPath, "File")
# Set the Action as Database to generate a FULL backup
$dbBackup.Action="Database"
# Call the SqlBackup method to complete backup
$dbBackup.SqlBackup($sqlServer)
Write-Host "Backup of database "$dbname" completed"
# Set SQL Server instance name
$sqlName= "localhost\SQLEXPRESS"
# Set new or existing databse name to restote backup
$dbname= "HamiltonXRP2"
# Set the existing backup file path
$backupPath= "C:\bin\HamiltonXRP_DB.bak"
# Stop the HamiltonXRP processes/service
Stop-Process -Name Hamilton.XRP2.Base.* -Force
#Load the required assemlies SMO and SmoExtended.
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoExtended") | Out-Null
# Connect SQL Server.
$sqlServer = New-Object ('Microsoft.SqlServer.Management.Smo.Server') $sqlName
# Create SMo Restore object instance
$dbRestore = new-object ("Microsoft.SqlServer.Management.Smo.Restore")
# Set database and backup file path
$dbRestore.Database = $dbname
$dbRestore.Devices.AddDevice($backupPath, "File")
# Set the databse file location
$dbRestoreFile = new-object("Microsoft.SqlServer.Management.Smo.RelocateFile")
$dbRestoreLog = new-object("Microsoft.SqlServer.Management.Smo.RelocateFile")
$dbRestoreFile.LogicalFileName = $dbname
$dbRestoreFile.PhysicalFileName = $sqlServer.Information.MasterDBPath + "\" + $dbRestore.Database + "_Data.mdf"
$dbRestoreLog.LogicalFileName = $dbname + "_Log"
$dbRestoreLog.PhysicalFileName = $sqlServer.Information.MasterDBLogPath + "\" + $dbRestore.Database + "_Log.ldf"
$dbRestore.RelocateFiles.Add($dbRestoreFile)
$dbRestore.RelocateFiles.Add($dbRestoreLog)
# Call the SqlRestore mathod to complete restore database
$dbRestore.SqlRestore($sqlServer)
Write-Host "SQL Database "$dbname" Restored Successfully"
import sys
from msvcrt import getch as pause
from zipfile import ZipFile
from xml.etree import ElementTree
from tkinter import Tk as tk
from tkinter.filedialog import askopenfilename
### Functions
def selectFile():
# if running from windows shell, use args
if len(sys.argv) > 1:
path = sys.argv[1]
# if running from other program, use file browser
else:
tk().withdraw()
path = askopenfilename(filetypes=[('Hamilton Files','*.ham*')])
return path
## Get the contents of a file inside a zip file, formatted as a tree
def getXMLTreeFromZip(zip_path, filename):
zip = ZipFile(zip_path)
contents = zip.read(filename)
return ElementTree.fromstring(contents)
## Get the human-readable names for each dependency node for the document
def getNodeNames(zip_path, root):
attrib_names = []
for child in root:
docname = child.get('ZipEntryName')
root_node = getXMLTreeFromZip(zip_path, docname)
view_name = '{} ({})'.format(child.get('Name'),root_node.get('ViewName'))
attrib_names.append(view_name)
return attrib_names
## Print the names with some fancy `tree` lines
def printNames(name_list):
print(' ' + name_list[0])
for child in name_list[1:-1]:
print(' ├───' + child)
print(' └───' + name_list[-1])
## Main
def main():
# select ham file
zip_path = selectFile()
# get contents of dependency list
contents = getXMLTreeFromZip(zip_path, 'Contents.xml')
# get the names of the nodes
node_names = getNodeNames(zip_path, contents)
# print the names
printNames(node_names)
# wait to exit
pause()
### Main
if __name__ == "__main__":
# execute only if run as a script
main()
#NoTrayIcon
#SingleInstance Force
SendMode Input
; Win+A : Open Chrome
#A::
Run, "chrome.exe"
Return
; Win+B : Send an email
#B::
Run, "mailto://"
Return
; Win+C : Start command line (in local directory if possible)
#C::
if WinActive("ahk_class CabinetWClass")
{
WinGetText, title_text, A
address_pos_beg := RegExMatch(title_text, "(?<=Address: ).")
address_pos_end := RegExMatch(title_text, "\r\n")
address_pos_len := address_pos_end - address_pos_beg
addr := SubStr(title_text, address_pos_beg, address_pos_len)
; fix Windows libraries not acting like directories
addr := RegExReplace(addr, "^Libraries\\", "C:\Users\" . A_UserName . "\")
}
else
{
addr = C:\Users\%A_UserName%
}
Run, "C:\Windows\System32\cmd.exe" "/K cd /d %addr%"
Return
; Win+G: Adjust window width to golden ratio
#G::
WinGetPos, ,, Width, Height, A
NewWidth := Round(Height*1.61803398875)
WinMove, A, ,,, NewWidth, Height
Return
; Win+H: Adjust window height to golden ratio
#H::
WinGetPos, ,, Width, Height, A
NewHeight := Round(Width/1.61803398875)
WinMove, A, ,,, Width, NewHeight
Return
; Win+M: Toggle screen zoom (Windows Magnify tool)
#M::
IfWinNotExist ahk_exe Magnify.exe
Run, "C:\Windows\system32\Magnify.exe"
else
WinClose, Magnifier
Return
; Win+N : Bring Notepad++ up, or minimize if focused
#N::
IfWinActive ahk_class Notepad++
WinMinimize
else
Run, "C:\Program Files (x86)\Notepad++\notepad++.exe"
Return
; Win+S : Start the Windows Snipping Tool
#S::
Run, "C:\Windows\system32\SnippingTool.exe"
Return
; Win+F9: Toggle desktop icons
#F9::
ControlGet, hwnd, Hwnd,, SysListView321, ahk_class Progman
If DllCall("IsWindowVisible", UInt,hwnd)
WinHide, ahk_id %hwnd%
Else
WinShow, ahk_id %hwnd%
return
; Win+Alt+Left/Right : Mirror window to other side of monitor
#!Left::
#!Right::
; Get information about the active window
WinGetTitle, hwnd, A
WinGetPos, hwndX, hwndY, hwndWidth, hwndHeight, %hwnd%
; Window Midpoint
windowMidpoint := hwndX + (hwndWidth/2)
; Retrieve information about the monitor the window's midpoint is on
SysGet, monCount, MonitorCount
Loop %monCount%
{ SysGet, curMon, Monitor, %a_index%
if ( windowMidpoint >= curMonLeft and windowMidpoint <= curMonRight and hwndY >= curMonTop and hwndY <= curMonBottom )
{
monitorX := curMonLeft
monitorWidth := curMonRight - curMonLeft
break
}
}
; Absolute X-Midpoint of Current Monitor
absoluteHalfScreenWidth := monitorX + (monitorWidth/2)
; Difference between the middle of the screen and window's midpoint
difference := windowMidpoint - absoluteHalfScreenWidth
; Mirror the window midpoint over the halfway point
newX := windowMidpoint - (2 * difference) - (hwndWidth)/2
WinMove, %hwnd%, , newX, hwndY
Return
; Ctrl+V : Allow pasting into Console windows
#IfWinActive ahk_class ConsoleWindowClass
^V::
SendInput {Raw}%clipboard%
return
#IfWinActive
; Ctrl+Shift+V : Paste as plain text
^+v:: ; Text–only paste from ClipBoard
Clip0 = %ClipBoardAll%
ClipBoard = %ClipBoard% ; Convert to text
Send ^v ; For best compatibility: SendPlay
Sleep 50 ; Don't change clipboard while it is pasted! (Sleep > 0)
ClipBoard = %Clip0% ; Restore original ClipBoard
VarSetCapacity(Clip0, 0) ; Free memory
Return
; Ctrl+' : Input a checkmark
^'::
Send ✓
Return
; Ctrl+? : Help dialog
^/::
^+/::
MsgBox,
(
Win+A : Open Chrome
Win+B : Send an email
Win+C : Start command line (in local directory if possible)
Win+G : Adjust window width to golden ratio
Win+H : Adjust window height to golden ratio
Win+M : Toggle Windows Magnifier tool
Win+N : Bring Notepad++ up, or minimize if focused
Win+S : Start the Windows Snipping Tool
Win+F9: Toggle desktop icons
Win+Alt+Left/Right : Mirror window to other side of monitor
Ctrl+V : Allow pasting into Console windows
Ctrl+' : Input a checkmark
Ctrl+? : Help dialog
Ctrl+F12 : Restart HamiltonXRP Service
Ctrl+Alt+F12 : Restart HamiltonXRP Service (with TRP enabled)
Ctrl+Shift+V : Paste as plain text
Alt+P : Enter passwords for IV/VSphere
Alt+F12 : Input current Instinct V version
)
Return
; Ctrl+F12 : Restart HamiltonXRP Service (without TRP enabled)
^F12::
runwait, %SystemRoot%\syswow64\WindowsPowerShell\v1.0\powershell.exe "Start-Process powershell -ArgumentList '-ExecutionPolicy Bypass -File C:\bin\Restart-HamiltonXRP_Service.ps1 false'"
Return
; Ctrl+Alt+F12 : Restart HamiltonXRP Service (with TRP enabled)
!^F12::
runwait, %SystemRoot%\syswow64\WindowsPowerShell\v1.0\powershell.exe "Start-Process powershell -ArgumentList '-ExecutionPolicy Bypass -File C:\bin\Restart-HamiltonXRP_Service.ps1 true'"
Return
; Alt+F12 : Input current Instinct V version (from RunMaster)
!F12::
RefreshEnvironment()
EnvGet, WorkbenchVersion, XRP2Version
if (!WorkbenchVersion) ; if env var is blank or does not exist, grab it off the exe
{
; Get raw version string
EnvGet, XRP2, XRP2BaseDir
FileGetVersion, WorkbenchVersion, %XRP2%\Bin\Hamilton.XRP2.Base.WorkbenchUI.exe
; Split version string into parts
Array := StrSplit(WorkbenchVersion, ".")
; Fix version string formatting (properly padded to 5 digits)
WorkbenchVersion := BuildVersionString(Array)
}
Send %WorkbenchVersion%
Return
; -----
BuildVersionString(array)
{
CatStr := array[1] "." array[2] "." Pad( array[3] ) "." Pad( array[4] )
Return CatStr
}
Pad(PadStr)
{
SetFormat, float, 05.0
PadStr += 0.0
Return PadStr
}
RefreshEnvironment()
{
Path := ""
PathExt := ""
RegKeys := "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment,HKCU\Environment"
Loop, Parse, RegKeys, CSV
{
Loop, Reg, %A_LoopField%, V
{
RegRead, Value
If (A_LoopRegType == "REG_EXPAND_SZ" && !ExpandEnvironmentStrings(Value))
Continue
If (A_LoopRegName = "PATH")
Path .= Value . ";"
Else If (A_LoopRegName = "PATHEXT")
PathExt .= Value . ";"
Else
EnvSet, %A_LoopRegName%, %Value%
}
}
EnvSet, PATH, %Path%
EnvSet, PATHEXT, %PathExt%
}
ExpandEnvironmentStrings(ByRef vInputString)
{
; get the required size for the expanded string
vSizeNeeded := DllCall("ExpandEnvironmentStrings", "Str", vInputString, "Int", 0, "Int", 0)
If (vSizeNeeded == "" || vSizeNeeded <= 0)
return False ; unable to get the size for the expanded string for some reason
vByteSize := vSizeNeeded + 1
If (A_PtrSize == 8) { ; Only 64-Bit builds of AHK_L will return 8, all others will be 4 or blank
vByteSize *= 2 ; need to expand to wide character sizes
}
VarSetCapacity(vTempValue, vByteSize, 0)
; attempt to expand the environment string
If (!DllCall("ExpandEnvironmentStrings", "Str", vInputString, "Str", vTempValue, "Int", vSizeNeeded))
return False ; unable to expand the environment string
vInputString := vTempValue
; return success
Return True
}
[Rainmeter]
SkinPath=C:\Users\fredrickson_m\Documents\Rainmeter\Skins\
Logging=1
ConfigEditor=C:\Program Files (x86)\Notepad++\notepad++.exe
;-----------------------
; META
;-----------------------
; BARS
[Enigma\Sidebar]
Active=1
WindowX=3640
WindowY=0
LoadOrder=-1
AlwaysOnTop=-2
ClickThrough=1
Draggable=0
SnapEdges=1
KeepOnScreen=1
AlphaValue=255
HideOnMouseOver=0
;-----------------------
; SIDEBAR
[Enigma\Sidebar\System]
Active=1
WindowX=3640
WindowY=63
ClickThrough=1
Draggable=0
SnapEdges=1
KeepOnScreen=1
AlwaysOnTop=0
HideOnMouseOver=0
[Enigma\Sidebar\Music]
Active=1
WindowX=3640
WindowY=1000
ClickThrough=0
Draggable=0
SnapEdges=1
KeepOnScreen=1
AlwaysOnTop=0
HideOnMouseOver=0
AutoSelectScreen=0
;-----------------------
; TASKBAR
[Enigma\Sidebar\Network]
Active=1
WindowX=3640
WindowY=215
ClickThrough=1
Draggable=0
SnapEdges=1
KeepOnScreen=1
AlwaysOnTop=0
HideOnMouseOver=0
[Monstercat Visualizer]
Active=1
WindowX=1920
WindowY=907
ClickThrough=1
Draggable=1
SnapEdges=1
KeepOnScreen=1
AlwaysOnTop=2
AlphaValue=101
[Monstercat Visualizer\Song Information]
Active=3
WindowX=1920
WindowY=0
ClickThrough=1
Draggable=1
SnapEdges=1
KeepOnScreen=1
AlwaysOnTop=2
AlphaValue=152
HideOnMouseOver=1
[Minimal System Info\White\Uptime]
Active=1
WindowX=3669
WindowY=532
ClickThrough=1
Draggable=0
SnapEdges=1
KeepOnScreen=1
AlwaysOnTop=0
[Enigma\Sidebar\Process]
Active=1
WindowX=3640
WindowY=367
ClickThrough=1
Draggable=0
SnapEdges=1
KeepOnScreen=1
AlwaysOnTop=0
HideOnMouseOver=0
[Enigma\Sidebar\Calendar]
Active=1
WindowX=3640
WindowY=0
ClickThrough=1
Draggable=0
SnapEdges=1
KeepOnScreen=1
AlwaysOnTop=0
LoadOrder=0
HideOnMouseOver=0
[Enigma\Sidebar\Volume]
Active=1
WindowX=3640
WindowY=951
ClickThrough=0
Draggable=0
SnapEdges=1
KeepOnScreen=1
AlwaysOnTop=0
HideOnMouseOver=0
[Enigma\Sidebar\_Sidebar2]
Active=1
WindowX=3440
WindowY=0
ClickThrough=1
Draggable=0
SnapEdges=1
KeepOnScreen=1
AlwaysOnTop=-2
LoadOrder=-1
[custom\Road]
Active=1
WindowX=3450
WindowY=10
ClickThrough=0
Draggable=0
SnapEdges=1
KeepOnScreen=1
AlwaysOnTop=0
$TRP=[System.Convert]::ToBoolean($args[0])
Write-Host "Stopping all XRP2 processes..."
Stop-Process -Name Hamilton.XRP2.Base.* -Force
Write-Host "HamiltonXRP service has been shut down."
Start-Sleep -Seconds 5
Write-Host "Starting HamiltonXRP service" -NoNewLine
if($TRP -eq $True)
{
Write-Host " (with TRP)" -ForegroundColor "red" -NoNewLine
}
Write-Host "..."
$service = get-service HamiltonXRP;
if($service.Status -ne 'Running')
{
if ($TRP -eq $True)
{
$service.start("/dump TRP /trp C:\TRP")
}
else
{
$service.start("")
}
while ((get-service HamiltonXRP).Status -ne 'Running')
{
Write-Host "WARNING: Waiting for service 'Hamilton XRP-2 Service (HamiltonXRP)' to finish`n starting..." -ForegroundColor "yellow"
Start-Sleep -Seconds 2
}
}
Write-Host "Successfully started HamiltonXRP service."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
$workbench = (get-item env:"XRP2BaseDir").Value + "\Bin\"
Start-Process -Filepath ($workbench + "Hamilton.XRP2.Base.WorkbenchUI.exe") -ArgumentList "-cid MainProgram" -WorkingDirectory $workbench
#NoEnv
#SingleInstance Force
#Persistent
; Create the tray menu
Menu, Tray, NoStandard ; Clears out the default menu items
Menu, Tray, Add, Open INSTINCT V, OpenInstinctV
Menu, Tray, Add, Open Run Control, OpenRunControl
Menu, Tray, Add ; separator
Menu, Tray, Add, Copy INSTINCT V Version, GetInstinctVVersion
Menu, Tray, Add, Open INSTINCT V Folder, OpenInstinctVFolder
Menu, Tray, Add ; separator
Menu, Tray, Add, Assay Dependency Viewer, DepView
Menu, Tray, Add, Restart HamiltonXRP Service, RestartService
Menu, Tray, Add, Restart HamiltonXRP Service (w/ TRP), RestartServiceTRP
Menu, Tray, Add, Restore Database, RestoreDatabase
Menu, Tray, Add ; separator
Menu, Tray, Add, Reload, ReloadScript
Menu, Tray, Add, Exit, KillScript
Menu, Tray, Default, Open INSTINCT V
Menu, Tray, Tip, INSTINCT V Tool
Return
; Labels for the menu
OpenInstinctV:
OpenSoftware("MainProgram")
Return
OpenRunControl:
OpenSoftware("RunControl")
Return
GetInstinctVVersion:
RefreshEnvironment()
EnvGet, WorkbenchVersion, XRP2Version
if (!WorkbenchVersion) ; if env var is blank or does not exist, grab it off the exe
{
; Get raw version string
EnvGet, XRP2, XRP2BaseDir
FileGetVersion, WorkbenchVersion, %XRP2%\Bin\Hamilton.XRP2.Base.WorkbenchUI.exe
; Split version string into parts
Array := StrSplit(WorkbenchVersion, ".")
; Fix version string formatting (properly padded to 5 digits)
WorkbenchVersion := BuildVersionString(Array)
}
MsgBox, , Version, v%WorkbenchVersion%
clipboard = %WorkbenchVersion%
Return
OpenInstinctVFolder:
RefreshEnvironment()
EnvGet, XRP2, XRP2BaseDir
Run explorer.exe "%XRP2%\Bin" `,/e
Return
DepView:
Run,C:\bin\depview.py
Return
RestartService:
EnvGet, root, SystemRoot
runwait, %root%\syswow64\WindowsPowerShell\v1.0\powershell.exe "Start-Process powershell -ArgumentList '-ExecutionPolicy Bypass -File C:\bin\Restart-HamiltonXRP_Service.ps1 false'"
Return
RestartServiceTRP:
EnvGet, root, SystemRoot
runwait, %root%\syswow64\WindowsPowerShell\v1.0\powershell.exe "Start-Process powershell -ArgumentList '-ExecutionPolicy Bypass -File C:\bin\Restart-HamiltonXRP_Service.ps1 true'"
Return
RestoreDatabase:
EnvGet, root, SystemRoot
runwait, %root%\syswow64\WindowsPowerShell\v1.0\powershell.exe "Start-Process powershell -ArgumentList '-ExecutionPolicy Bypass -File C:\bin\Restart-HamiltonXRP_Service.ps1 false'"
runwait, %root%\syswow64\WindowsPowerShell\v1.0\powershell.exe "Start-Process powershell -ArgumentList '-ExecutionPolicy Bypass -File C:\bin\db_restore.ps1'"
Return
ReloadScript:
Reload
Sleep 1000
MsgBox, Reload failed.
Return
KillScript:
ExitApp
Return
; Methods
OpenSoftware(program)
{
; Get the XRP2BaseDir env var containing the path to Instinct V
RefreshEnvironment()
EnvGet, XRP2, XRP2BaseDir
; Determine if version is DLRM or not, and set password based on that
IfInString, XRP2, RunMaster
pw = 123456
IfNotInString, XRP2, RunMaster
pw = p@ssword
; Open the Workbench as Adminsys
SetWorkingDir, %XRP2%\Bin\
Run, Hamilton.XRP2.Base.WorkbenchUI.exe -cid %program% -sd "AdminSys %pw% localhost localhost" -sim
Return
}
BuildVersionString(array)
{
CatStr := array[1] "." array[2] "." Pad( array[3] ) "." Pad( array[4] )
Return CatStr
}
Pad(PadStr)
{
SetFormat, float, 05.0
PadStr += 0.0
Return PadStr
}
RefreshEnvironment()
{
Path := ""
PathExt := ""
RegKeys := "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment,HKCU\Environment"
Loop, Parse, RegKeys, CSV
{
Loop, Reg, %A_LoopField%, V
{
RegRead, Value
If (A_LoopRegType == "REG_EXPAND_SZ" && !ExpandEnvironmentStrings(Value))
Continue
If (A_LoopRegName = "PATH")
Path .= Value . ";"
Else If (A_LoopRegName = "PATHEXT")
PathExt .= Value . ";"
Else
EnvSet, %A_LoopRegName%, %Value%
}
}
EnvSet, PATH, %Path%
EnvSet, PATHEXT, %PathExt%
}
ExpandEnvironmentStrings(ByRef vInputString)
{
; get the required size for the expanded string
vSizeNeeded := DllCall("ExpandEnvironmentStrings", "Str", vInputString, "Int", 0, "Int", 0)
If (vSizeNeeded == "" || vSizeNeeded <= 0)
return False ; unable to get the size for the expanded string for some reason
vByteSize := vSizeNeeded + 1
If (A_PtrSize == 8) { ; Only 64-Bit builds of AHK_L will return 8, all others will be 4 or blank
vByteSize *= 2 ; need to expand to wide character sizes
}
VarSetCapacity(vTempValue, vByteSize, 0)
; attempt to expand the environment string
If (!DllCall("ExpandEnvironmentStrings", "Str", vInputString, "Str", vTempValue, "Int", vSizeNeeded))
return False ; unable to expand the environment string
vInputString := vTempValue
; return success
Return True
}
@matthewjberger
Copy link

me gusta

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment