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("{C8438CC2-32B2-41CC-A696-4BAE6568F396}{1}{B0}", "{C6500222-467D-4F01-938E-E60ED395BE17}{11}{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}"