applescript - Remove numbers in front of file[working] + append number to duplicate filenames[not-working] -



applescript - Remove numbers in front of file[working] + append number to duplicate filenames[not-working] -

i have applescript removes numbers and/or hyphens , underscores origin of filename. works fine. however, might have situation this:

filename eg; 01-dog.jpg, 02-dog.jpg, 03-dog.jpg, etc.

in such case, script stops/does not run, telling me there file name. not tell me file conflicting (sometimes there lot of files through).

could please help in modifying script in such case, file same name have number or letter appended end of filename (before extension).

eg; dog2.jpg, dog3.jpg, etc.

on run {input, parameters} repeat thisfile in input tell application "finder" set filename name of (thisfile alias) set filename (do shell script "echo " & quoted form of filename & " | sed 's/^[0-9_-]*//'") set name of thisfile filename end tell end repeat homecoming input end run

thank help!!

basically, want renaming within seek block, if errors, can add together 1, 2, 3... name , effort again. here's version work:

on run {input, parameters} repeat thisfile in input tell application "finder" set {thename, theextension} {name, name extension} of (thisfile alias) set thename text 1 thru ((offset of ("." & theextension) in thename) - 1) of thename set thename (do shell script "echo " & quoted form of thename & " | sed 's/^[0-9_-]*//'") set n "" repeat 30 times -- work 30 versions of same file name seek tell application "finder" set name of thisfile (thename & n & "." & theextension) exit repeat on error errmsg if errmsg contains "already item name" if n "" set n 2 else set n (n integer) + 1 end if else display dialog errmsg exit repeat end if end seek end repeat end repeat homecoming input end run

the offset line show how base of operations name of file. need capture base of operations name separate extension in order append 1, 2, 3… crazy finder dictionary has name extension property, not base of operations name property. however, i'd write truncating extension sed call. if have files without extension, need add together error check that.

applescript

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -