diff --git a/gnuSnapCode.py b/gnuSnapCode.py index 722339f..e54b940 100644 --- a/gnuSnapCode.py +++ b/gnuSnapCode.py @@ -1,5 +1,6 @@ #!/usr/bin/python import os +import tempfile import pyperclip from pygments import highlight from pygments.lexers import get_lexer_by_name @@ -12,8 +13,12 @@ lenguaje = get_lexer_by_name("python", stripall=True) # Recoger el codigo del Portapapeles codigo = pyperclip.paste() +# fichero temporal para nombre unico y no sobreescribir +fichero = tempfile.NamedTemporaryFile() +fichero.name += '.png' + # Generar la imagen -img = highlight(codigo, lenguaje, ImageFormatter(style='native'), outfile="/tmp/codigo.png") +img = highlight(codigo, lenguaje, ImageFormatter(style='native'), outfile=fichero.name) # Abrir la imagen generada -os.system('open /tmp/codigo.png') \ No newline at end of file +os.system('open ' + fichero.name) \ No newline at end of file