Thursday, July 17, 2014

Gimp Autosave Hack

I like Gimp, I really do. Yes, it has a learning curve, but it’s not unreasonable, considering all the tutorials and how-to videos available on the web. One thing has kept me from loving Gimp, at least until recently.

My laptop’s battery has been going downhill recently and sometimes won’t hold a charge for longer than 20-30 minutes so I keep it plugged in all the time. The problem is that my unreliable charging cable sometimes charges, sometimes doesn’t. So I experience more than the usual number of unexpected shutdowns (if I forget to diligently watch the battery meter). A project I have been working on has had me editing quite a few images in Gimp and also subsequently losing a lot of work when my computer dies without warning. I searched and searched for something that would work as an autosave feature since Gimp for Windows doesn’t come with that feature (it should).

Finally, I found something that works (as long as I remember to get it started when I start Gimp; next for something to automate that).

Here’s what you do: Download and install AutoHotKey. Create a script in notepad and save it as AutoSave.ahk (I keep mine on the desktop for easy access).

Paste this code (I have no idea if all of this is necessary, but it works):

;
; AutoHotkey Version: 1.x
; Language:       English
; Platform:       Win9x/NT
; Author:         A.N.Other <myemail@nowhere.com>
;
; Script Function:
;    Template script (you can customize this template by editing "ShellNew\Template.ahk" in your Windows folder)
;

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

 

#Persistent

; Save the file every one minute.
SetTimer, AutoSave, 60000, On

AutoSave:
   IfWinActive, ahk_class gdkWindowToplevel
      Send {Blind}^s
return

If you don’t want it to save every minute, just change the 60000 value to a multiple of 60000/minute.

You might have to change the “ahk_class gdkWindowToplevel” entry. With Gimp open and AutoHotKey running, I right clicked on the icon in my system tray and selected “Window Spy” which brought up a window with the ahk_class name next to it.