Skip to content

Instantly share code, notes, and snippets.

@apsun
Created October 20, 2015 00:09
Show Gist options
  • Select an option

  • Save apsun/5ba50ebcf572351d1b0e to your computer and use it in GitHub Desktop.

Select an option

Save apsun/5ba50ebcf572351d1b0e to your computer and use it in GitHub Desktop.
#NoEnv
#Warn
#NoTrayIcon
#SingleInstance force
#Include CommonFunctions.ahk
SendMode Input
;-----------------------------------------------------------------------------------------------
;------------------------------------------Toggle on/off----------------------------------------
;-----------------------------------------------------------------------------------------------
^!q::Suspend
;-----------------------------------------------------------------------------------------------
;------------------------------------------General macros---------------------------------------
;-----------------------------------------------------------------------------------------------
:*cb0:/lolnow::thereisnourflevel
;-----------------------------------------------------------------------------------------------
;-----------------------------------------Science-y macros--------------------------------------
;-----------------------------------------------------------------------------------------------
:*c:/deg::{U+00B0}
:*c:/plusminus::{U+00B1}
:*c:/+-::{U+00B1}
:*c:/square::{U+00B2}
:*c:/^2::{U+00B2}
:*c:/cube::{U+00B3}
:*c:/^3::{U+00B3}
:*c:/ae::{U+2248}
:*c:/~=::{U+2248}
:*c:/ne::{U+2260}
:*c:/!=::{U+2260}
:*c:/lte::{U+2264}
:*c:/<=::{U+2264}
:*c:/gte::{U+2265}
:*c:/>=::{U+2265}
:*c:/sqrt::{U+221A}
:*c:/alpha::{U+03B1}
:*c:/beta::{U+03B2}
:*c:/delta::{U+0394}
:*c:/sigma::{U+03A3}
:*c:/theta::{U+03B8}
:*c:/lambda::{U+03BB}
:*c:/omega::{U+03A9}
:*c:/pi::{U+03C0}
:*c:/copyright::{U+00A9}
:*c:/nazi::{U+5350}
:*c:/communist::{U+262D}
:*c:/jew::{U+2721}
;-----------------------------------------------------------------------------------------------
;-----------------------------------------MS Word macros----------------------------------------
;-----------------------------------------------------------------------------------------------
:*c:/headery::
SendWordHeader(true)
return
:*c:/headern::
SendWordHeader(false)
return
:*c:/enheadery::
SendWordHeader(true, "Mr. Kozel", "11 AP English Literature")
return
:*c:/enheadern::
SendWordHeader(false, "Mr. Kozel", "11 AP English Literature")
return
;-----------------------------------------------------------------------------------------------
;-------------------------------------------CSS macros------------------------------------------
;-----------------------------------------------------------------------------------------------
:*b0z://::
WinGetTitle, currTitle, A
IfInString, currTitle, .css - WebStorm
{
Send {Backspace}{Backspace}/* {End} */
Send {Left}{Left}{Left}
}
Return
;-----------------------------------------------------------------------------------------------
;----------------------------Below are functions, tread with caution!---------------------------
;-----------------------------------------------------------------------------------------------
; Sends a header for MS Word.
; If dateFormat evaluates to false ("" or 0), no date is output.
; If dateFormat is true (1), it will be replaced by the default format (MMMM d, yyyy).
; Any other inputs for dateFormat will be used as the format for the date.
; If subject or assignment evaluates to false ("" or 0), they will be replaced
; with the default text ([SUBJECT] and [ASSIGNMENT], respectively) and automatically
; selected after the macro executes.
SendWordHeader(dateFormat = "MMMM d, yyyy", teacher = "", subject = "", assignment = "")
{
hasTeacher := true
hasSubject := true
hasAssignment := true
if (dateFormat = true)
{
dateFormat := "MMMM d, yyyy"
}
if (!teacher)
{
hasTeacher := false
teacher := "[TEACHER]"
}
if (!subject)
{
hasSubject := false
subject := "[SUBJECT]"
}
if (!assignment)
{
hasAssignment := false
assignment := "[ASSIGNMENT]"
}
; Get today's date in specified format
date := ""
if (dateFormat)
{
FormatTime, date,, `n%dateFormat%
}
; CTRL-1 sets single-spacing
; CTRL-2 sets double-spacing
; CTRL-L sets left-align
; CTRL-R sets right-align
caretMacro := ""
if (!hasSubject || !hasAssignment)
{
; This moves the caret up and selects the template
; The left is there because MS Word likes to select the line break as well
; One right is for [, one for the word, one for ]
; This moves the caret up the needed amount of lines
caretMacroUp =
; This selects the template, one right is for [, one for the word, one for ]
; The left is there because MS Word likes to select the line break as well
caretMacroSelect = {Right}{Right}{Right}{Left}
; Select the next one as well if both are templates
if (!hasSubject && !hasAssignment)
{
caretMacroSelect = {Right}{Right}{Right}%caretMacroSelect%
}
if (!hasTeacher)
{
caretMacroUp = {Up}{Up}{Up}
if (dateFormat)
{
caretMacroUp = {Up}%caretMacroUp%
}
}
else if (!hasSubject)
{
caretMacroUp = {Up}{Up}
if (dateFormat)
{
caretMacroUp = {Up}%caretMacroUp%
}
}
else if (!hasAssignment)
{
caretMacroUp = {Up}
}
caretMacro = %caretMacroUp%{Ctrl Down}{Shift Down}%caretMacroSelect%{Shift Up}{Ctrl Up}
}
; Set the actual Word Document header
msWordDialogClass := "Net UI Tool Window"
msWordClass := "OpusApp"
msWordHeaderTabClass := "NetUICtrlNotifySink"
; Open header selector
Send {Alt}nnu
; Wait until selector is open
WaitClassActive(msWordDialogClass)
; Save HWND of header vertical alignment dialog
headerVertDialogHwnd := GetForegroundWindowHandle()
; Select "top of page" for page number location
Send t
; Wait until we've changed to the horizontal selection dialog
WaitHandleNotActive(headerVertDialogHwnd)
; Select the right-aligned header
Send {Down}{Down}{Enter}
; WaitClassExist(msWordHeaderTabClass)
; headerTabHwnd := GetHandleFromClass(msWordHeaderTabClass)
; Wait until we are back in the document
WaitClassActive(msWordClass)
; This is pretty buggy, maybe find a better way some time...
Send % "Sun "
Sleep, 1000 ; STOP SLEEPING YOU NOOB
Send {Alt}jhc
; WaitHandleNotExist(headerTabHwnd)
text =
(
^2^r^lAndrew Sun
%teacher%
%subject%%date%
^e%assignment%
^l%caretMacro%
)
Send %text%
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment