I am writing this script that renames PDFs on my desktop, and then moves them to the appropriate folder.
I have got the renaming part done. But for the life of me, I can’t figure out how to get the move part of the script to work.
Anyway, here’s the code:
-- Step One: Get a list of MWJ issues files on the desktop (as aliases)
tell application "Finder" to tell (files whose name begins with "MWJ_") to try
set fileList to it as alias list
on error
set fileList to it as alias as list
end try
-- Step Two: Check and see if there are *any * issues of MWJ in the desktop folder
if (count fileList) is 0 then display dialog "There are no issues of MWJ on the desktop." buttons {"Cancel"} default button 1
-- Step Three: Take the list that we created in the first step, and manipulate the name, and move it to the appropriate folder
repeat with i from 1 to (count fileList)
set currentFile to (item i of fileList as alias)
set currentInfo to info for currentFile
set currentName to the name of currentInfo
try
set currentYear to characters 5 through 8 of currentName as string
set currentMonth to (characters 9 through 10 of currentName) as string
set currentDay to (characters 11 through 12 of currentName) as string
set newName to ("MWJ " & currentMonth & "-" & currentDay & ".pdf") as text
tell application "Finder"
set the name of currentFile to newName
end tell
on error theErr
display dialog "Something went wrong. Error # " & theErr buttons {"Cancel"} default button 1
end try
try
set partPath to "Dylan:Users:tom:Documents:MWJ:"
set newPath to partPath & currentYear as string
tell application "Finder"
move currentFile to newPath
end tell
on error errTwo
display dialog errTwo buttons {"Cancel"} default button 1
end try
end repeat
I think the problem is with the newPath variable – it’s the wrong class. What should I be doing?
Thanks for any and all help,
Tom McKenna (a newbie who just finished AS: The Definitive Guide)