Skip to content

Instantly share code, notes, and snippets.

@srt4rulez
Last active March 28, 2022 11:44
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save srt4rulez/746cc6a86645466a393fd3b87fdc5357 to your computer and use it in GitHub Desktop.
Save srt4rulez/746cc6a86645466a393fd3b87fdc5357 to your computer and use it in GitHub Desktop.
Autohotkey
;-------------------------------------------------------------------------------
; Jake's AutoHotKey.ahk
;
; For Reference:
;
; Hotkey Modifiers
; # - Windows key
; ! - Alt
; ^ - Control
; + - Shift
;
;-------------------------------------------------------------------------------
;-------------------------------------------------------------------------------
; TABLE OF CONTENTS
;
; VARIABLES
; INCLUDES
; HOTKEYS START HERE - GENERICS
; WIN+KEY HOTKEYS
; WIN+SHIFT+KEY HOTKEYS
; CTRL+ALT+KEY HOTKEYS
; CTRL+SHIFT+KEY HOTKEYS
; CTRL+WIN+KEY HOTKEYS - MOSTLY SHORTCUTS
; OPEN FILE IN PROGRAM HOTKEYS
; HOTSTRING DATES
; HOTSTRINGS
; RANDOM HOTSTRINGS/HOTKEYS
; CODE
; HOME HOTKEYS
; SLEEP, HIBERANATE, AND SHUTDOWN HOTKEYS
; ALT+SHIFT+KEY HOTKEYS
;-------------------------------------------------------------------------------
;-------------------------------------------------------------------------------
; VARIABLES
;-------------------------------------------------------------------------------
global Display := "Computer"
global FanProfile := "Gaming"
global shortcutDir := "C:\Users\Jake\Documents\Shortcuts\"
; Clover class
global cloverClass := "Clover_WidgetWin_0"
; Chrome class + path
global chromeClass := "Chrome_WidgetWin_1"
global chromePath := "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
; DropBox window name + path
global dropWName := "Dropbox"
global dropPath := shortcutDir . "Dropbox"
; Download name + path
global downloadWName := "Downloads"
global downloadPath := "A:\Downloads"
; EVERYTHING search class + path
global everythingClass := "EVERYTHING"
global everythingPath := shortcutDir . "Everything"
; Firefox path
global firefoxPath := "C:\Program Files (x86)\Mozilla Firefox\firefox.exe"
; Git Extentions class + path
global gitExtentionClass := "WindowsForms10.Window.8.app.0.2f5a4f0_r11_ad1"
global gitExtentionPath := "C:\Program Files (x86)\GitExtensions\GitExtensions.exe"
global hostsClass := "WindowsForms10.Window.8.app.0.34f5582_r11_ad1"
global hostsPath := shortcutDir . "Hosts"
; IrfanView class + path
global irfanViewClass := "IrfanView"
global irfanViewPath := shortcutDir . "IrfanView"
; Internet Explorer path
global iePath := shortcutDir . "IE"
; My Documents window name
global mydocWName := "My Documents"
; My Pictures windows name
global mypicturesWNmae := "My Pictures"
global mypicturePath := "C:\Users\Jake\Pictures"
; Photoshop path
global photoshopPath := shortcutDir . "Photoshop"
; Sublime Text 3 class + path
global sublimeClass := "PX_WINDOW_CLASS"
global sublimePath := "C:\Program Files\Sublime Text 3\sublime_text.exe"
; Atom Path
global atomPath := "C:\Users\Jake\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\GitHub, Inc\Atom.lnk"
; Thunderbird class + path
global thunderbirdClass := "MozillaWindowClass"
global thunderbirdPath := shortcutDir . "Thunderbird"
; WinSCP class + path
global scpClass := "TScpCommanderForm"
global scpPath := shortcutDir . "WinSCP"
; www window name + path
global wwwWName := "www"
global wwwPath := shortcutDir . "www"
; wamp server path
global wampPath := shortcutDir . "WampServer"
; jake-vm window name + path
global jakeVMWindowName := "J:\"
global jakeVMPath := shortcutDir . "jake-vm"
;-------------------------------------------------------------------------------
; HALIGHT / EXOMARK
;-------------------------------------------------------------------------------
global workingPath := shortcutDir . "Working"
global coldFusionWebsitesPath := shortcutDir . "ColdFusion"
global clientWName := "Clients"
global clientPath := "C:\Users\Jake\Documents\Clients"
global jdennisonPath := shortcutDir . "jdennison"
global hipchatClass := "Qt5QWindowIcon"
global hipchatPath := shortcutDir . "Hipchat"
;-------------------------------------------------------------------------------
; INCLUDES
;-------------------------------------------------------------------------------
; RandomVar for xrand, which create a random password,
; configurable via the hotstring
#Include, RandomVar.ahk
; Functions, for custom AHK functions
#Include, Functions.ahk
; AutoCorrect
; from: http://www.autohotkey.com/docs/Hotstrings.htm
#Include, AutoCorrect.ahk
; Private hotstrings
#Include, Private.ahk
; KeyList
#Include, KeyList.ahk
;-------------------------------------------------------------------------------
; HOTKEYS START HERE - GENERICS
;-------------------------------------------------------------------------------
; # Windows Key
; ! Alt
; ^ Control
; + Shift
; CTRL+WIN+ALT+4
; Opens this AHK Script for editing
^!#4::
{
Edit
Return
}
; CTRL+S
; Auto-reload AHK scripts if a .ahk file is open in Atom
#IfWinActive ahk_class Chrome_WidgetWin_1
$^s::
{
Send, ^s
SetTitleMatchMode 2
IfWinActive, .ahk
{
TrayTip, Timed TrayTip, Updated AutoHotkey script
SetTimer, RemoveTrayTip, 1000
}
Return
#IfWinActive
}
RemoveTrayTip:
SetTimer, RemoveTrayTip, Off
TrayTip
Reload
Return
;-------------------------------------------------------------------------------
; WIN+KEY HOTKEYS
;-------------------------------------------------------------------------------
; WIN+M
; Minimizes current window
#m::
{
WinMinimize, A
Return
}
; WIN+C
; Opens CMD in the current dir
#c::
{
openShellInCurrent("conemu")
Return
}
; WIN+G
; Open Git Extentions Browser in current dir
#g::
{
#IfWinActive ahk_class CabinetWClass
OpenFileInProgram("C:\Program Files (x86)\GitExtensions\GitExtensions.exe browse")
#IfWinActive
Return
}
;-------------------------------------------------------------------------------
; WIN+SHIFT+KEY HOTKEYS
;-------------------------------------------------------------------------------
; Converts selected text to title case
; WIN+SHIFT+T
#+t::
{
convertCaseTo("Title")
Return
}
; Converts selected text to uppercase
; WIN+SHIFT+U
#+u::
{
convertCaseTo("Upper")
Return
}
; Converts selected text to lowercase
; WIN+SHIFT+L
#+l::
{
convertCaseTo("Lower")
Return
}
;-------------------------------------------------------------------------------
; CTRL+ALT+KEY HOTKEYS
;-------------------------------------------------------------------------------
; Toggle AHK Suspend
; CTRL+ALT+F12
^!F12::Suspend
; Copies selected text, converts to lowercase, replaces spaces/underscores with dashes,
; removes extra dashes with only 1 dash
; CTRL+ALT+C
^!c::
{
oldClipBoard := clipboard ; save clipboard so you don't lose what you had
Clipboard := ; clear the clipboard
SendInput, ^c ; copy the current text
ClipWait, 2
IfErrorMsg("Error", "The attempt to copy text onto the clipboard failed.")
StringLower, string, clipboard ; converts clipboard to lowercase
StringReplace, string, string, %A_SPACE%, -, All ; replace all spaces ( ) with dashes (-)
StringReplace, string, string, _, -, All ; replace all underscores (_) with dashes (-)
; Replace all duplicate dashes and replace them with only 1 dash
string := RegExReplace(string, "([\-]){2,}", "-")
Clipboard := ; clear clipboard again
Clipboard := string
ClipWait, 2
IfErrorMsg("Error", "The attempt to copy formatted string to the clipboard failed.")
SendInput, ^v ; paste newly formatted file name with lowercase + dashes!
Sleep, 1000 ; delay of 1s, or else you will end up pasting old clip content instead of new string
Clipboard := oldClipBoard
ClipWait, 2
IfErrorMsg("Error", "Old clipboard content could not be retrieved. (Timeout of 2)")
Return
}
; Copies selected text, replaces dash/underscores with spaces, converts text to title case
; CTRL+ALT+V
^!v::
{
oldClipBoard := clipboard ; save clipboard so you don't lose what you had
Clipboard := ; clear the clipboard
SendInput, ^c ; copy the current text
ClipWait, 2
IfErrorMsg("Error", "The attempt to copy text onto the clipboard failed.")
string := clipboard ; store clipboard content in string var
StringReplace, string, string, -, %A_SPACE%, All ; replace all dashes (-) with spaces ( )
StringReplace, string, string, _, %A_SPACE%, All ; replace all underscores (_) with spaces ( )
StringLower, string, string, T ; converts string to title case
Clipboard := ; clear clipboard again
Clipboard := string
ClipWait, 2
IfErrorMsg("Error", "The attempt to copy formatted string to the clipboard failed.")
SendInput, ^v ; paste newly formatted file name with lowercase + dashes!
Sleep, 1000 ; delay of 1s, or else you will end up pasting old clip content instead of new string
Clipboard := oldClipBoard
ClipWait, 2
IfErrorMsg("Error", "Old clipboard content could not be retrieved. (Timeout of 2)")
Return
}
; CTRL+ALT+/
; Open Everything Search
^!/::
{
openOrCloseProgram(everythingClass, everythingPath)
Return
}
; CTRL+ALT+T
; Copies chrome's address bar link, opens FF and IE with address
; (for browser dev testing)
^!t::
{
SendInput, ^l ; select chrome's address bar
Sleep, 500
address := getSelectedText()
Run, iexplore.exe %address%, C:\Program Files\Internet Explorer, UseErrorLevel
ifErrorMsg("Error", "Error: Could not launch IE.")
Run, firefox.exe %address%, C:\Program Files (x86)\Mozilla Firefox, UseErrorLevel
ifErrorMsg("Error", "Error: Could not launch Firefox.")
Return
}
;-------------------------------------------------------------------------------
; CTRL+SHIFT+KEY HOTKEYS
;-------------------------------------------------------------------------------
; Sends current link to wp-admin for Chrome
; CTRL+SHIFT+A
^+a::
{
IfWinActive, ahk_class %chromeClass%
{
SendInput, {Ctrl down}l{Ctrl up}
Sleep 50
SendInput {Right}
Sleep 50
SendInput {Shift down}{Left}{Shift up}
Sleep 50
result := getSelectedText()
Sleep 50
SendInput {Right}
Sleep 50
if (result = "/") {
SendInput wp-admin
}
else {
SendInput /wp-admin
}
SendInput {Enter}
Return
}
Return
}
; Goes to /?g_hooks=show for the Genesis Visual Hook Guide WP Plugin
; CTRL+SHIFT+G
^+g::
{
IfWinActive, ahk_class %chromeClass%
{
SendInput, {Ctrl down}l{Ctrl up}
Sleep 50
SendInput {Right}
Sleep 50
SendInput {Shift down}{Ctrl down}{Left 2}{Shift up}{Ctrl up}
Sleep 50
result := getSelectedText()
if (result = "g_hooks=show") {
SendInput {Shift down}{Left}{Shift up}
Sleep 50
SendInput {Del}
Sleep 50
}
else {
SendInput {Right}
SendInput ?g_hooks=show
Sleep 50
}
SendInput {Enter}
Return
}
Return
}
; CTRL+SHIFT+L
; creates link - Only activates if Thunderbird is active class
; Sends current link to /wp-login.php for Chrome
^+l::
{
IfWinActive, ahk_class %thunderbirdClass%
{
SendInput, ^l
WinWait, ahk_class MozillaDialogClass
IfErrorMsg("Error", "Error: WinWait timed out")
SendInput, ^v
Sleep, 250
SendInput, {Tab}
Sleep, 250
SendInput, ^v
Sleep, 250
SendInput, {Enter}
Return
}
IfWinActive, ahk_class %chromeClass%
{
SendInput, {Ctrl down}l{Ctrl up}
Sleep 50
SendInput {Right}
Sleep 50
SendInput /wp-login.php
SendInput {Enter}
Return
}
Return
}
; CTRL+SHIFT+T
; create new text file (to match Windows' Ctrl+Shift+N for new folders)
; Prompt for name and then open it in Sublime Text
; Only activates if Clover is active class
^+t::
{
IfWinActive ahk_class CabinetWClass
{
newTextFile()
Return
}
Return
}
;-------------------------------------------------------------------------------
; CTRL+WIN+KEY HOTKEYS - MOSTLY SHORTCUTS
;-------------------------------------------------------------------------------
; CTRL+WIN+V
; Opens Jake VM
^#v::
{
openOrCloseDir(jakeVMWindowName, jakeVMPath)
Return
}
; CTRL+WIN+H
; Opens HipChat
^#h::
{
openOrCloseProgram(hipchatClass, hipchatPath)
Return
}
; CTRL+WIN+L
; Open or close Downloads folder
^#l::
{
openOrCloseDir(downloadWName, downloadPath)
Return
}
; CTRL+WIN+UP
; Set sound to +2, show volume in right hand corner
^#Up::
{
Progress, Off
SoundSet, +2 ; this number is how much it changes in volume
SoundGet, master_volume
IfErrorMsg("Error", "Error: Can't get master volume")
mv := Round(master_volume)
Progress, M2 b fs32 zh0 x1600 y955 ,Volume: %mv%`%, , , Tahoma
SetTimer, sound_timer, 500
SetTimer, volume_timer, 2500
Return
}
; CTRL+WIN+DOWN
; Set sound to -2, show volume in right hand corner
^#Down::
{
Progress, Off
SoundSet, -2 ; this number is how much it changes in volume
SoundGet, master_volume
IfErrorMsg("Error", "Error: Can't get master volume")
mv := Round(master_volume)
Progress, M2 b fs32 zh0 x1600 y955 ,Volume: %mv%`%, , , Tahoma
SetTimer, sound_timer, 500
SetTimer, volume_timer, 2500
Return
}
; CTRL+WIN+F
; Open or close WinSCP
^#f::
{
openOrCloseProgram(scpClass, scpPath)
Return
}
; CTRL+WIN+A
; Open or activate Atom
^#a::
{
SetTitleMatchMode, 2
openOrActivateTitle("Atom", atomPath)
Return
}
; CTRL+WIN+G
; Open or minimize GTalk
; ^#g::
; {
; openOrMinimizeProgram(gtalkClass, gtalkPath)
; Return
; }
; CTRL+WIN+W
; Open or close wamp www folder
^#w::
{
openOrCloseDir(wwwWName, wwwPath)
Return
}
; CTRL+WIN+D
; Open or close My Documents folder
^#d::
{
openOrCloseDir(mydocWName, A_MyDocuments)
Return
}
; CTRL+WIN+P
; Open or close My Pictures folder
^#p::
{
openOrCloseDir(mypicturesWNmae, mypicturePath)
Return
}
; CTRL+WIN+Z
; Open or close Working directory
^#z::
{
openOrCloseDir("Working", workingPath)
Return
}
; CTRL+WIN+K
; Open or close ColdFusion directory
^#k::
{
openOrCloseDir("Websites", coldFusionWebsitesPath)
Return
}
^#j::
{
openOrCloseDir("jdennison", jdennisonPath)
Return
}
; CTRL+WIN+X
; Activates Chromes Dev Tools (needs checks)
^#x::
{
; openOrCloseDir(clientWName, clientPath)
WinActivate, Developer Tools
Return
}
; CTRL+WIN+S
; Open or Activate Sublime Text 3
^#s::
{
openOrActivate(sublimeClass, sublimePath)
Return
}
; CTRL+WIN+B
; Open or close DropBox
^#b::
{
openOrCloseDir(dropWName, dropPath)
Return
}
; CTRL+WIN+C
; Open or activate Chrome
^#c::
{
SetTitleMatchMode, 2
openOrActivateTitle("Google Chrome", chromePath)
Return
}
; CTRL+WIN+T
; Open or minimize Thunderbird
^#t::
{
openOrMinimizeProgram(thunderbirdClass, thunderbirdPath)
Return
}
; Ctrl+Win+E
; Activate current Clover Window
^#e::
{
WinActivate, ahk_class %cloverClass%
Return
}
;-------------------------------------------------------------------------------
; OPEN FILE IN PROGRAM HOTKEYS
;-------------------------------------------------------------------------------
; WIN+F1
; Open file in Atom / Open Folder as project in Atom
#F1::
{
openFileInProgram("Atom")
Return
}
; WIN+F3
; Open file in IrfanView
#F3::
{
openFileInProgram(irfanViewPath)
Return
}
; WIN+F4
; Open file in Adobe Photoshop
#F4::
{
; openFileInProgram(photoshopPath)
openFileInProgram("Photoshop")
Return
}
; Set all Hotstrings below to trim right space (o), and be case sensitive
#Hotstring oc
;-------------------------------------------------------------------------------
; HOTSTRING DATES
;-------------------------------------------------------------------------------
; type "mysqldate" to enter current date in year-day-month format | Ex. 2015-02-26
::mysqldate::
{
FormatTime, CurrentDateTime,, yyyy-MM-dd
SendInput %CurrentDateTime%
Return
}
; type "cdate" to enter current date in month/day/year format | Ex. 02/14/2014
::cdate::
{
FormatTime, CurrentDateTime,, MM/d/yyyy
SendInput %CurrentDateTime%
Return
}
; type "cddate" to enter current date in month-day-year format | Ex. 02-14-2014
::cddate::
{
FormatTime, CurrentDateTime,, MM-d-yyyy
SendInput %CurrentDateTime%
Return
}
; type "fdate" to enter current date in dayofweek, month day, year | Ex. Friday, February 14, 2014
::fdate::
{
FormatTime, CurrentDateTime,, dddd, MMMM d, yyyy
SendInput %CurrentDateTime%
Return
}
; type "thedate" to enter the current date in month, year | Ex. April 2014
::thedate::
{
FormatTime, CurrentDateTime,, MMMM yyyy
SendInput %CurrentDateTime%
Return
}
; type "sdate" to enter the current date in month-day-year | Ex. Feb-18-2014
::sdate::
{
FormatTime, CurrentDateTime,, MMM-dd-yyyy
SendInput %CurrentDateTime%
Return
}
; Enwin date | Ex. Sep 29/14
::edate::
{
FormatTime, CurrentDateTime,, MMM dd/y
SendInput %CurrentDateTime%
Return
}
; Enwin update date | Ex. 111814
::enwindate::
{
FormatTime, CurrentDateTime,, MMddyyyy
SendInput %CurrentDateTime%
Return
}
;-------------------------------------------------------------------------------
; HOTSTRINGS
;-------------------------------------------------------------------------------
; Git Commands
::xgs::git status
::xgc::git commit -m
::xgca::git commit -a -m
::xga::git add -A
::xgp::git pull -r origin master
::xgpd::git pull origin develop
::xvr::vertical rhythm
::xwpu::Wordpress / Server Updates
::xclick::$('input[value="1"]').click();
::xline::--------------------------------------------------
; type "xrand" for random password
; eg: 9KjquzQhorWb0mfW
::xrand::
{
randomPass := RandomVar(16,16,"alnum")
Send %randomPass%
Return
}
; type "xrandnum" for random numbers
; eg: 390656
::xrandnum::
{
randomNum := RandomVar(6,6,"integer")
SendInput, %randomNum%
Return
}
; type "xenwin" to have custom template typed out
::xenwin::
{
; Input box for the site name (Enwin / WUC)
InputBox, site, Site?, Enwin or WUC?, , 375, 125, , , , , Enwin
if (ErrorLevel)
{
MsgBox, Error cancel was pressed.
Return
}
; Input box for the person requesting the update
InputBox, person, Contact?, Who requested the update?, , 375, 125, , , , , Chantelle
if (ErrorLevel)
{
MsgBox, Error cancel was pressed.
Return
}
; Input box for the actual updates
InputBox, update, Updates?, List the updates., , 375, 125
if (ErrorLevel)
{
MsgBox, Error cancel was pressed.
Return
}
; Input box for the update time
InputBox, updateTime, Time?, Total time for update., , 375, 125
if (ErrorLevel)
{
MsgBox, Error cancel was pressed.
Return
}
; Current date (hotstring was not working?)
FormatTime, CurrentDateTime,, dddd, MMMM d, yyyy
; Send the formatted information from the input boxes
SendInput, Date: %CurrentDateTime%{Enter}
SendInput, Site: %site%{Enter}Requested By: %person%{Enter}Updated: %update%{Enter}Time: %updateTime% min{Enter}
SendInput, {Enter}--------------------------------------------------{Enter}{Enter}
Return
}
;-------------------------------------------------------------------------------
; RANDOM HOTSTRINGS/HOTKEYS
;-------------------------------------------------------------------------------
; CTRL+V pasting in CMD windows
#IfWinActive ahk_class ConsoleWindowClass
^V::SendInput {Raw}%clipboard%
#IfWinActive
::xrefresh::You may need to refresh to see the changes.
::xtest::This is a test. Please ignore.
::xdesc::description
::xcr::chrome://restart
;-------------------------------------------------------------------------------
; CODE
;-------------------------------------------------------------------------------
::xwpackagist::composer require wpackagist-plugin/plugin:dev-trunk
::xatom::atom --disable-direct-write
::xcopy::©
::xreg::®
::x404::ErrorDocument 404 /404.php
::xr301::Redirect 301 /
::xdrarrow::»
::xdlarrow::«
::xrarrow::→
::xlarrow::←
::xbr::<br />
::xhr::<hr />
::xbsp::&nbsp;
::xlorem::Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla lorem augue, egestas scelerisque imperdiet semper, imperdiet eu diam. Pellentesque vulputate nunc eget est malesuada eleifend. Sed mollis convallis tempor. Nulla sed convallis eros. Proin lectus ante, commodo ac euismod at, dignissim eget orci. Suspendisse molestie magna laoreet tellus condimentum tempus. In adipiscing suscipit lobortis.
::xview::<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
::xie::<meta http-equiv="x-ua-compatible" content="ie=edge">
;-------------------------------------------------------------------------------
; HOME HOTKEYS
;-------------------------------------------------------------------------------
; WIN+SHIFT+A
; Switch audio devices quickly (speakers to headphones and vise-versa)
#+a::
{
SwitchAudioDevices()
Return
}
; WIN+SHIFT+S
; Switch from computer monitor to TV (and vise-versa) , change fan mode,
; switches audio devices, then open Netflix
#+s::
{
SwitchDisplay()
Return
}
; WIN+SHIFT+F
; Launch AI Suite and switch loaded profile (Gaming to Movies/Movies to Gaming)
#+f::
{
SwitchFan()
Return
}
; WIN+SHIFT+G
; Toggle Flux
#+g::
{
toggleFlux()
Return
}
;-------------------------------------------------------------------------------
; SLEEP, HIBERANATE, AND SHUTDOWN HOTKEYS
;-------------------------------------------------------------------------------
; WIN+F10
; Sleep Computer
#F10::
{
DllCall("PowrProf\SetSuspendState", "int", 0, "int", 0, "int", 0)
Return
}
; WIN+F11
; Hibernate Computer
#F11::
{
DllCall("PowrProf\SetSuspendState", "int", 1, "int", 0, "int", 0)
Return
}
; WIN+F12
; Shutdown Computer
#F12::
{
Shutdown, 8
Return
}
;-------------------------------------------------------------------------------
; ALT+SHIFT+KEY HOTKEYS
;-------------------------------------------------------------------------------
; ALT+SHIFT+D
; Send ALT+F4 (close current window) - easier on the hands vs alt + f4
!+d::
{
SendInput, !{F4}
Return
}
; ALT+SHIFT+L
; Run KeyList
!+l::
{
ViewKeyList(A_ScriptFullPath)
}
;------------------------------------------------------------------------------
; Jake's Functions.ahk
;
; For Reference:
;
; Hotkey Modifiers
; # - Windows key
; ! - Alt
; ^ - Control
; + - Shift
;
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; TABLE OF CONTENTS
;
; switchDisplay
; switchAudioDevices
; switchAudioDevicesTV
; switchFan
; toggleFlux
; openOrCloseProgram
; openOrCloseDir
; openOrMinimizeProgram
; openOrActivate
; openOrActivateTitle
; openOrActivateText
; openFileInProgram
; newTextFile
; ifErrorMsg
; volume_timer
; sound_timer
; openShellInCurrent
; getSelectedText
; convertCaseTo
; killProgram
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; FUNCTIONS
;------------------------------------------------------------------------------
; Switch Display (& Switch Fan, Switch Audio Device, & Open Netflix)
switchDisplay() {
; if Display is set to Computer, switch to TV
global
local vProgramChoice
if (Display = "Computer") {
; Pick TV Output option
Gui, Font, s12, Lato ; set font to Lato, 14 point
Gui, Margin, 25, 25 ; set 25px margin, x/y
Gui, Add, Radio, Checked vProgramChoice, Netflix - &Edge ; choice 1
Gui, Add, Radio, , Netflix - &Chrome ; choice 2
Gui, Add, Radio, , Netflix - &Firefox ; choice 3
Gui, Add, Radio, , &XBMC ; choice 4
Gui, Add, Radio, , &Steam - Big Picture Mode ; choice 5
Gui, Add, Radio, , Downloads (For VLC) ; choice 6
Gui, Add, Button, x25 y280 w85 h35 Default, Launch ; "Launch" button
Gui, Add, Button, x116 y280 w85 h35, Cancel ; "Cancel" button
Gui, Show, W300, Choose program: ; show GUI, width of 250, title of "Choose program"
Return
; Cancel button action
ButtonCancel:
{
Gui, Destroy
Return
}
; Launch button action
ButtonLaunch:
{
Gui, Submit
If (ProgramChoice = 1)
{
program := "Edge"
}
If (ProgramChoice = 2)
{
program := "Chrome"
}
If (ProgramChoice = 3)
{
program := "Firefox"
}
If (ProgramChoice = 4)
{
program := "XBMC"
}
If (ProgramChoice = 5)
{
program := "Big Picture"
}
If (ProgramChoice = 6)
{
program := "VLC"
}
Gui, Destroy
}
SendInput, #p
Sleep 1000
SendInput, {Down}{Enter}{Esc}
Sleep 1000
; Switch fan based on current mode
; switchFan()
; Toggle Flux Moive Mode
toggleFlux("movie")
; Switch Audo Device to TV
SwitchAudioDevicesTV()
If (program = "Edge") {
Run, C:\Windows\explorer.exe shell:Appsfolder\Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge, UseErrorLevel
ifErrorMsg("Error", "Error: Could not launch Edge.")
launchXpadder()
}
If (program = "Chrome") {
Run, %chromePath% "http://movies.netflix.com/WiHome", UseErrorLevel
ifErrorMsg("Error", "Error: Could not launch Chrome.")
launchXpadder()
}
If (program = "Firefox") {
Run, %firefoxPath% "http://movies.netflix.com/WiHome", UseErrorLevel
ifErrorMsg("Error", "Error: Could not launch Firefox.")
launchXpadder()
}
If (program = "XBMC") {
Run, C:\Program Files (x86)\XBMC\XBMC.exe
ifErrorMsg("Error", "Error: Could not launch XBMC.")
}
If (program = "Big Picture") {
Run, "C:\Program Files (x86)\Steam\Steam.exe" steam://open/bigpicture
ifErrorMsg("Error", "Error: Could not launch Big Picture.")
}
If (program = "VLC") {
openOrCloseDir(downloadWName, downloadPath)
}
Display := "TV"
Return
}
; else if Display is set to TV, switch back to computer monitor
else if (Display == "TV") {
SendInput, #p
Sleep 1000
SendInput, {Down 3}{Enter}{Esc}
Sleep 1000
; Switch Fan
; switchFan()
; Toggle Flux Movie Mode
toggleFlux("movie")
; Switch audio device back
switchAudioDevicesTV()
; Kill xpadder
closeXpadder()
; killProgram("Xpadder.exe")
Display := "Computer"
Return
}
}
; Switch Audio Devices
switchAudioDevices() {
Run, mmsys.cpl
WinWait, Sound
ControlSend, SysListView321, {Down}
ControlGet, isEnabled, Enabled, ,&Set Default
if(!isEnabled) {
ControlSend,SysListView321, {Down 2}
}
ControlClick, &Set Default
ControlClick, OK
WinWaitClose
SoundPlay, *-1
}
; Switch Audio Device for TV to monitor and vice-versa
switchAudioDevicesTV() {
Run, mmsys.cpl
WinWait, Sound
if (Display == "TV") {
ControlClick, x151 y123, Sound
}
else if (Display == "Computer") {
ControlSend, SysListView321, {Down}
}
ControlClick, &Set Default, Sound
ControlClick, OK, Sound
WinWaitClose, Sound
SoundPlay, *-1
}
; Switch AI Suite II Fan Profile
; If FanProfile is Gaming, switch to Movies. (and vise-versa)
switchFan() {
if (FanProfile = "Gaming") {
; Switch FanProfile to Movies
Delay = 250
DownArrowNumber = 6
FanProfile := "Movies"
}
else if (FanProfile = "Movies") {
; Switch FanProfile to Gaming
Delay = 250
DownArrowNumber = 5
FanProfile := "Gaming"
}
Run, AI Suite II.exe, C:\Program Files (x86)\ASUS\AI Suite II
WinWait, AI Suite II
ControlClick, Tool, ahk_class TfrmBarGadget
Sleep, 250
ControlClick, FAN Xpert 2, ahk_class TL2SelectorForm
Sleep, %Delay%
ControlClick, Load, ahk_class TfrmFanXpert2
Sleep, 250
Send, {Down %DownArrowNumber%}
Sleep, 250
ControlClick, Load, ahk_class TfrmFxFile
ControlClick, GsButton2, ahk_class TMainForm
}
; Toggle Flux
; Pass in no parameters to toggle 'disable until sunrise' or 'movie' to toggle movie mode
toggleFlux(mode := "none") {
up := 3
If (mode == "movie") {
up := 6
}
; Run flux.exe
Run, C:\Users\Jake\AppData\Local\FluxSoftware\Flux\flux.exe
; Wait for window to be active
WinWait, ahk_class ytWindow
; Click the hamburger menu
ControlClick, X525 Y42
ifErrorMsg("Error", "Error: Could not click hamburger menu option.")
; Move up %up% and hit enter to toggle enable/disable/movie mode
SendInput, {Up %up%}{Enter}
Sleep 250
; Click close button
ControlClick, X542 Y14
Return
}
; Launch Xpadder for Xbox 360 Controller
launchXpadder() {
Run, C:\Program Files (x86)\Xpadder\Xpadder.exe
WinWait, ahk_class TXpadderForm
WinClose, ahk_class TXpadderForm
Return
; ControlClick, X407 Y13
}
; Close Xpadder
closeXpadder() {
Process, Close, Xpadder.exe
Return
}
; Open or Close program
openOrCloseProgram(programClass, path) {
IfWinExist, ahk_class %programClass%
{
IfWinActive, ahk_class %programClass%
{
WinClose, ahk_class %programClass%
Return
}
IfWinNotActive, ahk_class %programClass%
{
WinActivate, ahk_class %programClass%
Return
}
}
IfWinNotExist, ahk_class %programClass%
{
Run, "%path%", ,UseErrorLevel
IfErrorMsg("Error", "Error: Could not find the path: " . path)
Return
}
}
; Open or Close directory
openOrCloseDir(windowName, directory) {
IfWinExist, %windowName%
{
IfWinActive, %windowName%
{
WinClose, %windowName%
Return
}
IfWinNotActive, %windowName%
{
WinActivate, %windowName%
Return
}
}
IfWinNotExist, %windowName%
{
Run, "%directory%", ,UseErrorLevel
IfErrorMsg("Error", "Error: Could not find the directory: " . directory)
Return
}
}
; Open or Minimize program
openOrMinimizeProgram(programClass, path) {
IfWinActive, ahk_class %programClass%
{
WinMinimize, ahk_class %programClass%
Return
}
IfWinNotActive, ahk_class %programClass%
{
Run, %path%, ,UseErrorLevel
IfErrorMsg("Error", "Error: Could not find the path:" . path)
Return
}
Return
}
; Open or Activate program
openOrActivate(programClass, path) {
IfWinExist, ahk_class %programClass%
{
IfWinNotActive, ahk_class %programClass%
{
WinActivate, ahk_class %programClass%
Return
}
Return
}
IfWinNotExist, ahk_class %programClass%
{
Run, %path%, ,UseErrorLevel
IfErrorMsg("Error", "Error: Could not find the path: " . path)
Return
}
Return
}
; Open or Activate program (title)
openOrActivateTitle(programTitle, path) {
IfWinExist, %programTitle%
{
IfWinNotActive, %programTitle%
{
WinActivate, %programTitle%
Return
}
Return
}
IfWinNotExist, %programTitle%
{
Run, %path%, ,UseErrorLevel
IfErrorMsg("Error", "Error: Could not find the path: " . path)
Return
}
Return
}
; Open or Activate program (text)
openOrActivateText(programText, path) {
IfWinExist, ,%programText%
{
IfWinNotActive, ,%programText%
{
WinActivate, ,%programText%
Return
}
Return
}
IfWinNotExist, ,%programText%
{
Run, %path%, ,UseErrorLevel
IfErrorMsg("Error", "Error: Could not find the path: " . path)
Return
}
Return
}
; Open file in program
openFileInProgram(pathToProgram) {
; see: getSelectedText() function
pathToFile := getSelectedText()
if (!pathToFile) {
MsgBox No path, exiting
Return
}
if (pathToProgram == "Atom") {
Run, C:\Users\Jake\AppData\Local\atom\Update.exe --processStart atom.exe -a "%pathToFile% --disable-direct-write", ,UseErrorLevel
IfErrorMsg("Error", "Atom could not be opened")
Return
}
if (pathToProgram == "Photoshop") {
Run, C:\Program Files\Adobe\Adobe Photoshop CC 2014\Photoshop.exe "%pathToFile%", ,UseErrorLevel
IfErrorMsg("Error", "Error")
Return
}
Run, "%pathToProgram%" "%pathToFile%", ,UseErrorLevel
IfErrorMsg("Error", "Error: Could not open " . pathToProgram)
Return
}
; NewTextFile function
newTextFile() {
; Get full path from open Explorer window
WinGetText, FullPath, A
; Split up result (it returns paths separated by newlines)
StringSplit, PathArray, FullPath, `n
; Get first item
FullPath = %PathArray1%
; Clean up result
FullPath := RegExReplace(FullPath, "(^Address: )", "")
StringReplace, FullPath, FullPath, `r, , all
; Change working directory
SetWorkingDir, %FullPath%
; An error occurred with the SetWorkingDir directive
IfErrorMsg("Error", "An error occurred with the SetWorkingDir directive")
; Display input box for filename
InputBox, UserInput, New File Name (including .extension), , , 400, 120
; User pressed cancel
If (ErrorLevel) {
Return
}
; Create file
FileAppend, , %UserInput%
; Open the file in the appropriate editor
Run "%sublimePath%" "%UserInput%"
Return
}
; Check if error level, and if so, show message box with message, and break
ifErrorMsg(title, text) {
If (ErrorLevel) {
MsgBox, 48, %title%, %text%
Return
}
}
; Timer for showing the volume via progress
volume_timer:
{
SetTimer, volume_timer, Off
Progress, Off
Return
}
; Timer for playing the window audio sound
sound_timer:
{
SoundPlay, *-1
SetTimer, sound_timer, Off
Return
}
; Opens the a command shell in the directory browsed in Explorer.
; Note: expecting to be run when the active window is Explorer.
openShellInCurrent(shell) {
; This is required to get the full path of the file from the address bar
WinGetText, full_path, A
; Split on newline (`n)
StringSplit, word_array, full_path, `n
; Find and take the element from the array that contains address
Loop, %word_array0%
{
IfInString, word_array%A_Index%, Address
{
full_path := word_array%A_Index%
break
}
}
; strip to bare address
full_path := RegExReplace(full_path, "^Address: ", "")
; Just in case - remove all carriage returns (`r)
StringReplace, full_path, full_path, `r, , all
IfInString full_path, \
{
if (shell = "powershell") {
Run, powershell.exe -noexit -windowstyle "Maximized" -command "cd %full_path%"
}
else if (shell = "conemu") {
Run, ConEmu64.exe -Single -dir %full_path%
}
else if (shell = "cmd") {
Run, cmd /K cd /D "%full_path%"
}
}
; Default action if can't find dir
else
{
; if (shell = "git")
; {
; Run, "C:\Program Files (x86)\Git\bin\sh.exe" --login -i --cd %full_path%
; }
if (shell = "powershell") {
Run, powershell.exe -noexit -windowstyle "Maximized" -command "cd ~"
}
else if (shell = "cmd") {
Run, cmd /K cd /D "C:\ "
}
}
}
; Saves clipboard, copies selected text, store in variable, return clipboard,
; then return the selected text
getSelectedText() {
; Save Clipboard to variable
SavedClipBoard := ClipboardAll
; Clear Clipboard
Clipboard := ""
; Copy the current highlighted text
SendInput ^c
; Wait for Clipboard to contain something
ClipWait, 2, 1
IfErrorMsg("Error", "The attempt to copy text onto the clipboard failed.")
; Store Clipboard into variable
Result := Clipboard
; Return Clipboard contents to original data
Clipboard := SavedClipBoard
; Return selected text
Return Result
}
convertCaseTo(case) {
; Save Clipboard to variable
SavedClipBoard := ClipboardAll
; Clear Clipboard
Clipboard := ""
; Copy the current highlighted text
SendInput ^c
; Wait for Clipboard to contain something
ClipWait, 2, 1
IfErrorMsg("Error", "The attempt to copy text onto the clipboard failed.")
; Store Clipboard into variable
Result := Clipboard
if (case = "Title")
{
; Convert string to title case (Title Case)
StringUpper, Result, Result, T
}
else if (case = "Upper")
{
; Convert string to upper case (UPPERCASE)
StringUpper, Result, Result
}
else if (case = "Lower")
{
; Convert string to lower case (lowercase)
StringLower, Result, Result
}
else
{
MsgBox Case not supported.
Return
}
; Set clipboard contents to converted case
Clipboard := Result
; Paste back
SendInput ^v
Sleep, 1000 ; delay of 1s, or else you will end up pasting old clip content
; Return Clipboard contents to original data
Clipboard := SavedClipBoard
ClipWait, 2
IfErrorMsg("Error", "Old clipboard content could not be retrieved. (Timeout of 2)")
Return
}
killProgram(exe) {
Process, Close, %exe%
Return
}
/*
RandomVar.ahk
Copyright (C) 2009 Antonio França
This script is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This script is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this script. If not, see <http://www.gnu.org/licenses/>.
*/
;========================================================================
;
; Function: RandomVar
; Description: Returns a random content (with optional type)
; URL (+info): http://bit.ly/QJUt8A
;
; Last Update: 25/August/2009 01:30 BRT
;
; Created by MasterFocus
; - https://github.com/MasterFocus
; - http://masterfocus.ahk4.net
; - http://autohotkey.com/community/viewtopic.php?f=2&t=88198
;
;========================================================================
RandomVar(p_MinLength,p_MaxLength,p_Type="",p_MinAsc=32,p_MaxAsc=126)
{
; Old method, using RegExReplace - slower and harder to understand
; p_Type := RegExReplace(RegExReplace(RegExReplace(p_Type,"!","",l_Neg),"#","@",l_Cse),"@","",l_Rep)
; New method, using StringReplace - better in performance and readability
StringReplace,p_Type,p_Type,!,,All
l_Neg := !ErrorLevel
StringReplace,p_Type,p_Type,#,@,All
l_Cse := !ErrorLevel
StringReplace,p_Type,p_Type,@,,All
l_Rep := !ErrorLevel
Random, l_Aux, %p_MinLength%, %p_MaxLength%
Loop, %l_Aux% {
Loop {
Random, l_Aux, %p_MinAsc%, %p_MaxAsc%
l_Aux := Chr(l_Aux)
If ( !l_Rep ) OR ( l_Rep AND !InStr(l_Output,l_Aux,l_Cse) ) {
If p_Type not in integer,number,digit,xdigit,alpha,upper,lower,alnum,space
break
Else
If l_Neg {
If l_Aux is not %p_Type%
break
}
Else
If l_Aux is %p_Type%
break
}
}
l_Output .= l_Aux
}
return l_Output
}
@akaleeroy
Copy link

akaleeroy commented Feb 21, 2019

toggleFlux() can be done a bit better.

UI automation but from tray icon

Install TrayIcon.ahk library

#Include <TrayIcon>
; Programmatic right-click on flux.exe tray icon
TrayIcon_Button("flux.exe", "R")

; Navigate to Disable > for fullscreen apps
SetKeyDelay, 100 ; Won't work well without delay
SendEvent, {Up 3}{Right}{F}{Enter}

👍 Less coupled to UI details
👎 Still UI automation
👎 Not hidden in the background

Registry write and restart process

f.lux saves its preferences in the Registry but doesn't monitor them so changing them manually won't take without restarting the app.

setFluxFullscreenDisable(1)

restartFlux() {
  Process, Close, flux.exe
  Run, %LOCALAPPDATA%\FluxSoftware\Flux\flux.exe, , Hide
}

setFluxFullscreenDisable(val := "toggle") {
  fluxPrefs = HKEY_CURRENT_USER\Software\Michael Herf\flux\Preferences
  setting = fullscreendisable

  ; Read current setting value
  RegRead, currentVal, %fluxPrefs%, %setting%
  ; No valid argument passed, toggle current value
  val := !(val = 0 or val = 1) ? !currentVal : val

  ; Write new value
  RegWrite, REG_DWORD, %fluxPrefs%, %setting%, %val%
  restartFlux()

  return val
}

👎 Restart required
👍 Not UI automation
👍 Hidden in the background

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