Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Auto save plug-in for GIMP [2.8, 2.9]
#!/usr/bin/env python
# Original (by yahvuu): http://www.gimpusers.com/forums/gimp-developer/11718-autosave-plugin
import tempfile, os
from time import *
from gimpfu import *
def autosave(image, layer):
backupInterval = 10 * 60
backupFiles = {}
print "Autosave activated"
while 1:
sleep(backupInterval)
print ctime(time())
curImages = {}
for k in gimp.image_list():
curImages[k.ID] = k
curIDs = curImages.keys()
oldIDs = backupFiles.keys()
newIDs = [x for x in curIDs if x not in oldIDs]; delIDs = [x for x in oldIDs if x not in curIDs];
# create (empty) backup files for new images
for id in newIDs:
prefix = 'gimpbackup-ID' + str(id) + '-'
fn = tempfile.mkstemp(prefix = prefix, suffix = '.xcf')
os.close(fn[0])
backupFiles[id] = fn[1]
# remove closed images' backups
for id in delIDs:
filename = backupFiles[id]
del(backupFiles[id])
try:
os.remove(filename)
except:
print "ERROR: ", sys.exc_info()[0]
# backup images
for id, filename in backupFiles.iteritems():
img = curImages[id]
try:
print "saving " + img.name + '-' + str(id) + ' to ' + filename
pdb.gimp_xcf_save(1, img, img.active_drawable, filename, filename)
except:
print "ERROR: ", sys.exc_info()[0]
register(
"autosave",
"Autosave dirty hack",
"Periodically saves all opened images to a %temp% directory",
"public domain",
"public domain",
"2016",
"<Image>/File/Activate Autosave",
"*",
[],
[],
autosave)
main()
@jayViant

This comment has been minimized.

Copy link

jayViant commented Oct 22, 2019

Thanks! Lost my work twice in the past few days, power cut and then a crash today :(
I find it absurd that GIMP does not have this built in yet, the bug report requesting auto-save is still open with comments from 15 years ago!

@ErtYwek

This comment has been minimized.

Copy link

ErtYwek commented Feb 21, 2020

Where does it save "all opened images"? Autosave function should be implemented in gimp cause its crash very often when you edit big [ 100mb+] xcf files

I find it absurd that GIMP does not have this built in yet, the bug report requesting auto-save is still open with comments from 15 years ago!

But still remember that GNU Image Manipulation Program is free of charge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.