Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- This is not meant to be used together with the Win+S Snip feature of Time Saver (use whichever feels best at a certain computerwork session). Place in %Temp% folder.
- In File Explorer go to: "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories" > "Snipping Tool" > Properties, and then change Target from:
- "%windir%\system32\SnippingTool.exe" to "%Temp%\Snipping Tool.ahk", and "Start in" from blank to "%Temp%" (then find it in the Start menu and pin to Start).
- */
- #Requires AutoHotkey 2.0
- #SingleInstance Force
- #NoTrayIcon
- #Include "C:\Users\%A_UserName%\Downloads\AutoHotkey\Lib\winrt.ahk-main\windows.ahk"
- Run("ms-screenclip:")
- HookEvent(EVENT_OBJECT_NAMECHANGE := 0x800C, HandleNameChangedSnipWinEvent)
- SetTimer(DismissSnipNotification, -600000) ; This sets the timer to 10 minutes
- HandleNameChangedSnipWinEvent(hWinEventHook, event, hWnd, *)
- {
- try
- if (WinGetTitle(hWnd) = "Snip & Sketch" && WinGetClass(hWnd) = "ApplicationFrameWindow")
- {
- Sleep(100)
- WinClose(hWnd)
- ; Save clipboard image to temp folder to see its width and height (overwrites any that might've been saved in the past)
- RunWait("PowerShell.exe -Command `"$img = get-clipboard -format image; $img.save('" A_Temp "\latestSnip.jpg')`"",, "Hide")
- imageSize := GetImageSize(A_Temp "\latestSnip.jpg")
- ; The extra space is for the paint toolset ofcourse
- rawPaintWinWidth := imageSize.Width + 27
- rawPaintWinHeight := imageSize.Height + 192
- ; Initializing the paint wnd size (without the minimum, it will hide the paint toolset and without the maximum, it will go beyond the screen boundaries)
- paintWinWidth := (rawPaintWinWidth >= 379 ? (rawPaintWinWidth <= A_ScreenWidth ? rawPaintWinWidth : A_ScreenWidth) : 379)
- paintWinHeight := (rawPaintWinHeight >= 251 ? (rawPaintWinHeight <= A_ScreenHeight ? rawPaintWinHeight : A_ScreenHeight) : 251)
- Run("mspaint.exe",, "Min")
- WinWait("ahk_exe mspaint.exe")
- WinSetTransparent(0)
- if (paintWinWidth = A_ScreenWidth && paintWinHeight = A_ScreenHeight)
- {
- WinMaximize()
- Send("^v^+x") ; Pastes the image from clipboard and removes any white space that might remain
- }
- else
- {
- WinActivate()
- Send("^v^+x") ; Pastes the image from clipboard and removes any white space that might remain
- WinRestore() ; Unmaximize if it's maximized
- WinMove((A_ScreenWidth / 2) - (paintWinWidth / 2), (A_ScreenHeight / 2) - (paintWinHeight / 2), paintWinWidth, paintWinHeight) ; Moves to center w/ new size
- }
- WinSetTransparent("Off")
- ExitApp()
- }
- }
- GetImageSize(imagePath)
- {
- static shellObj := ComObject("Shell.Application")
- SplitPath(imagePath, &fileName, &fileDir)
- folderObj := shellObj.Namespace(fileDir)
- if (!folderItemObj := folderObj.ParseName(fileName))
- throw ValueError("The image path does not contain a (valid) file", -1, imagePath)
- sizeArray := StrSplit(folderItemObj.ExtendedProperty("Dimensions"), " x ")
- ; Ad hoc object which allows you to see its properties with IntelliSense, usable w/ dot notation (image size w/o invisible characters)
- return {Width: LTrim(sizeArray[1], Chr(8234)), Height: RTrim(sizeArray[2], Chr(8236))}
- }
- ; This gets rid of the snip notification, if it still exists
- DismissSnipNotification(*)
- {
- Windows.UI.Notifications.ToastNotificationManager.History.Clear("Microsoft.ScreenSketch_8wekyb3d8bbwe!App")
- ExitApp()
- }
- HookEvent(event, fnObj, pid := 0) => DllCall("SetWinEventHook", "UInt", event, "UInt", event, "Ptr", 0, "Ptr", CallbackCreate(fnObj), "UInt", pid, "UInt", 0, "UInt", 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement