0

I wrote a small script just to incremente a series of file names. I want to get a file named "111 - something.pdf" and rename it to "112 - something.pdf" But for some reason I'm getting this error:

error number -1728

set thisFile to choose file
tell application "System Events"
    set {tName, nameExt} to {name, name extension} of thisFile
    if nameExt is not "" then set nameExt to "." & nameExt
    set newName to my incrementNumber(tName, nameExt)
    if newName is not "" then
        set name of thisFile to newName
    end if
end tell


on incrementNumber(n, e) -- name and name extension
    set tNum to text 1 thru 3 of n
    set tBase to text 4 thru (length of n) of n
    try
        set newNumber to text (tNum + 1)
        display dialog newNumber
        set newName to text newNumber & tBase & e
        return newName
    end try
    return ""
end incrementNumber

I've tried to set newNumber to numbers, but it returns an array (1,1,1) nad not the full number. Anyone could help me?

  • You should use **coercion** as text instead of text specifier: **set newNumber to (tNum + 1) as text** and **set newName to newNumber & tBase**. Also, note in the last code line: adding e is no need – Robert Kniazidis Aug 11 '23 at 19:33

0 Answers0