Hi guys, this question is the sequal to my post “How can I pass a variable to an Idle block?”
This script involves staying open and monitoring a ‘process’ folder for new folders. It sorts through the new folder and any subfolders (if they exist) looking for tiffs. It opens the tiffs in Photoshop and does a few things and saves. The new folder is then moved to a ‘done’ folder. That’s the gist of it, and it works fine, BUT, I would also like the script to check each file and folder name for spaces, and take them out if they exist. IF any spaces existed in any file or folder, the script should move the new folder to a ‘relink’ folder (instead of ‘done’) for someone to update links in the page layout.
set procFolder to alias "path:to:Processing:"
set doneFolder to alias "path:to:Done:"
set relinkFolder to alias "path:to:Needs Relinking:"
set xyz to 0
global procFolder
global doneFolder
global relinkFolder
global xyz
on idle
tell application "Finder"
if first folder of procFolder exists then
set aFolder to first folder of procFolder
set itemList to items of aFolder
my initialCheck(itemList)
if xyz = 0 then
move aFolder to doneFolder
else
move aFolder to relinkFolder
end if
end if
end tell
return 1
end idle
on initialCheck(itemList)
tell application "Finder"
repeat with eachFile in itemList
if name of eachFile contains " " then my fixName(eachFile) -- *this is the problem*
if kind of eachFile is "folder" then
my checkSubFolder(eachFile)
else if file type of eachFile is "TIFF" then
open eachFile using application file id "8BIM"
my Photoshop() -- does the Photoshop thing
end if
end repeat
end tell
end initialCheck
on checkSubFolder(eachFile)
tell application "Finder"
set itemList to items of eachFile
my initialCheck(itemList)
end tell
end checkSubFolder
on fixName(eachFile)
tell application "Finder"
set itemName to name of eachFile
set AppleScript's text item delimiters to " "
set nameList to text items of itemName
set AppleScript's text item delimiters to ""
set newName to text items of nameList as string
set name of eachFile to newName
set xyz to 1
end tell
end fixName
The problem is (logically) that since the script changes the name of the file that was set to be ‘eachFile’, it then thinks the file no longer exists and errors when it tries the next step.
So, how can I change the name of ‘eachFile’ and still have the script be able to reference it? I tried coercing it to an alias without success, but maybe I did that wrong also.
Thanks again… 8)