1#Requires AutoHotkey v2.0
2OnError((exception, mode) => (FileAppend(exception.Message, "**"), ExitApp(1)))
3dm := Buffer(220, 0)
4NumPut("UShort", 220, dm, 68)
5if !DllCall("EnumDisplaySettingsW", "Ptr", 0, "UInt", 0xFFFFFFFF, "Ptr", dm)
6 throw Error("Cannot inspect display mode")
7NumPut("UInt", NumGet(dm, 72, "UInt") | 0x180000, dm, 72)
8NumPut("UInt", 1280, dm, 172)
9NumPut("UInt", 720, dm, 176)
10if DllCall("ChangeDisplaySettingsW", "Ptr", dm, "UInt", 0, "Int") != 0
11 throw Error("Display mode rejected")
12app := ComObject("OneNote.Application")
13app.NavigateTo("{36F927E2-894E-46B6-9880-230A50839CFA}{1}{B0}", "{E2A450C5-7596-4142-BBC7-E4EDC8853D7E}{50}{B0}", false)
14hwnd := WinWait("ahk_class Framework::CFrame ahk_exe ONENOTE.EXE",, 10)
15if !hwnd
16 throw Error("OneNote window did not appear")
17WinMaximize(hwnd)
18WinActivate(hwnd)
19if !WinWaitActive(hwnd,, 10)
20 throw Error("OneNote window did not become active")
21Sleep 300
22Send "{Left}{Backspace}"