omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular
    1. Home
    2. wm

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 4
    • Best 0
    • Controversial 0
    • Groups 0

    wm

    @wm

    0
    Reputation
    935
    Profile views
    4
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    wm Unfollow Follow

    Latest posts made by wm

    • RE: Increment and Save

      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
      wm
      wm
    • Increment and Save

      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.

      https://gist.github.com/weakmassive/2400bcca3ae2c0a6a43c

      posted in Pythonista
      wm
      wm
    • RE: Increment and Save

      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)
      #editor.reload_files()
      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)]
      		
      		try:
      			num = re.split('([0-9]+)$',noext)[1]
      			alist.append(int(num))
      			filename = noextnonum + str(max(alist)+1) + ext
      		except:
      			filename = noextnonum + str(1) + ext
      
      	x = x + 1
      
      editor.make_new_file(filename, text)
      
      posted in Pythonista
      wm
      wm
    • RE: Increment and Save

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

      posted in Pythonista
      wm
      wm