• wm

    Oh thank you - this is perfect! I knew there had to be an easier way than looping every file.

    It's just my personal preference to have the numbered files. There's an "increment and save" function in Adobe After Effects that I use for my job and I just wanted to replicate that. And on my phone the I can't really read the long timestamps.

    posted in Pythonista read more
  • wm

    This is a script that you can add to the Actions menu to duplicate the current script and add a number to it (or if it's numbered already, add one). I wanted a quick way to keep multiple iterations of a script.

    I just started learning Python last week, so I'm sure I could do things differently (let me know!), but it seems to working for my purposes and I didn't see anything similar already on here.


    posted in Pythonista read more
  • wm

    Thanks briarfox, I'll check out StaSh.

    I noticed my script wouldn't increment correctly if a file ending in a higher number already existed. For example, if I've got the files a1, a2, a3 and use the script on a2, it would give me "a3 1".

    I've attempted to fix this and it seems to be working but the code is not at all elegant. Any tips on easier ways to do this? Again, I'm really new to this so sorry for the crazy code! I don't really know what I'm doing. I also noticed it doesn't work in folders, but that's for another day.

    Here's the code:

    import os, sys, editor, re
    filepath = editor.get_path()
    filename = os.path.basename(filepath)
    ext1 = os.path.splitext(filepath)
    noext = filename[:-len(ext1)-1]
    noextnonum = re.split('([0-9]+)$',noext)[0]
    namelen = len(noextnonum)
    #filepath stuff
    path = os.path.dirname(filepath)
    files = os.listdir(path)
    text = editor.get_text()
    if not text:
        sys.exit('No text in the Editor.')
    alist = []
    x = 0
    while x<=len(files)-1:  
        if noextnonum == files[x][:namelen]:
            ext = os.path.splitext(files[x])[1]
            noext = files[x][:-len(ext)]
                num = re.split('([0-9]+)$',noext)[1]
                filename = noextnonum + str(max(alist)+1) + ext
                filename = noextnonum + str(1) + ext
        x = x + 1
    editor.make_new_file(filename, text)

    posted in Pythonista read more
  • wm

    Thank you! I've revised the script based on your comments over on Gist.

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!