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.10]
#!/usr/bin/env python
# Original (by yahvuu): http://www.gimpusers.com/forums/gimp-developer/11718-autosave-plugin
import tempfile
import os
from time import *
from gimpfu import *
def autosave(image, layer):
# Backup interval in seconds (600 = 10 minutes)
backup_interval = 10 * 60
print('Autosave activated')
backup_files = {}
while 1:
sleep(backup_interval)
print(ctime(time()))
cur_images = {}
for k in gimp.image_list():
cur_images[k.ID] = k
cur_ids = cur_images.keys()
old_ids = backup_files.keys()
new_ids = [x for x in cur_ids if x not in old_ids]
del_ids = [x for x in old_ids if x not in cur_ids]
# create (empty) backup files for new images
for id in new_ids:
prefix = 'gimpbackup-ID' + str(id) + '-'
fn = tempfile.mkstemp(prefix=prefix, suffix='.xcf')
os.close(fn[0])
backup_files[id] = fn[1]
# remove closed images' backups
for id in del_ids:
filename = backup_files[id]
del(backup_files[id])
try:
os.remove(filename)
except:
gimp.message('ERROR: ' + sys.exc_info()[0])
# backup images
for id, filename in backup_files.iteritems():
img = cur_images[id]
try:
print('Saving ' + img.name + '-' + str(id) + ' to ' + filename)
pdb.gimp_xcf_save(1, img, img.active_drawable, filename, filename)
except:
gimp.message('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()
@s0urc3ray

This comment has been minimized.

Copy link

@s0urc3ray s0urc3ray 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!

@TCWVyt

This comment has been minimized.

Copy link

@TCWVyt TCWVyt commented Dec 8, 2019

Does this script crash for anyone else? When I use it says it may have messed up the internal state of Gimp because the script has crashed

@crogonint

This comment has been minimized.

Copy link

@crogonint crogonint commented Dec 9, 2020

So.. this plug-in DOES go in the /home/username/.gimp-2.8/plug-ins/ folder

You do not have to jump through hoops downloading obscure packages to figure out how to register it in Gimp.
You do not have to do a bunch of top secret command crap in terminal.
You do not have to hack it in to the system directory or install a system Python version.
Once you have it in the proper folder, go to the file properties for the script and make it executable.
That is all.
God alone knows why.

If you still don't see it on the FIle menu the next time you open Gimp, close Gimp, go to the /home/username/.gimp-2.8/ folder and delete the pluginrc file. open Gimp again, and it will rediscover all of the add-ons.

Ta-Da!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment