AppleScript runs, but does not seem to work I have an excel workbook open, with old file names in column A and new file names in column B. I am attempting to use the applescript below to rename my files. It runs without errors, but doesn't rename the files. Am I missing something? Any help is much appreciated.

set theDirectory to "/Users/admin/Desktop/test/copied images"
tell application "Microsoft Excel"
    tell active sheet
        tell used range
            set rc to count of rows
        end tell
        set theList to get value of range ("A1:B" &amp; rc) as list
        repeat with theItem in theList
            try
                do shell script "mv " &amp; theDirectory &amp; "/" &amp; quoted form of item 1 of     theItem &amp; space &amp; theDirectory &amp; "/" &amp; quoted form of item 2 of theItem
            end try
        end repeat
    end tell
end tell
Why your script seems to run without errors

Your script runs without errors because it swallows any error that may occur in the do shell script line.

Temporarily remove the surrounding try and end try lines to un-mute the errors. This will likely lead to an error message that ends with No such file or directory.

Why your script does not rename files

The issue is that your script hands the value of theDirectory directly to the shell command without quoting it. Because that value contains spaces, the shell interprets the directory &amp;[…]theItem part as two separate arguments, which causes mv to fail.

Solution

In the do shell script line, replace both occurrences of


  theDirectory


with:


  quoted form of theDirectory


(Optional) Making your script more robust

Additionally, I suggest that you either lose the surrounding try/end try altogether, or alternatively insert an on error statement to handle possible errors that can occur in the do shell script part.

Writing scripts that don’t swallow errors means you’ll save time in the long run.