Well, I am pretty sure it’s me who’s not working right but I am stumped.
tell application "Finder"
set AOLRef to a reference to folder ((name of startup disk) & ":Users:Shared:America Online:")
set AOLAlias to AOLRef as alias -- returns alias "SI OS X:Users:Shared:America Online:"
set AOLPosix to POSIX path of AOLAlias -- returns "/Users/Shared/America Online/"
set dataFolders to the name of every folder in AOLRef whose name begins with "Data" -- returns {"Data 11/21/05 10.55.35 PM", "Data 12/6/05 10.23.35 PM", "Data 12/9/05 12.14.05 AM"}
set AOLLocations to the name of every item in folder "Temp" of AOLRef -- returns {"Dial 800", "Dial from Away", "Dial from Home", "NYC", "Office or TCPIP"}
repeat with dataFol in dataFolders
repeat with AOLLoc in AOLLocations
set source to (AOLPosix & "Temp/" & AOLLoc)
set destination to (AOLPosix & dataFol & "/")
do shell script "ditto -rsrc " & quoted form of source & " " & quoted form of destination
end repeat
end repeat
end tell
The script will run as a postinstall script for an installer that places a number of AOL location files in /Shared/American Online/Temp (later I’ll use a hidden location and clean up after the installer). The script will copy the location files into any folder found in /Shared/America Online/ whose name begins with ‘Data…’.
Everything seems to work fine, except ‘quoted form of’ doesn’t seem to protect the slashes in the destination. The folders are named with a timestamp, for instance: “Data 11/21/05 10.55.35 PM.” There’s is no knowing the exact name of these folders.
ditto interprets the slashes as subdirectories and creates these. cp, which I also tried, fails because the destination doesn’t exist. In both cases the slashes are the culprits.
Can anyone enlighten me? Why doesn’t ‘quoted form of’ work in this case?
I don’t think quoted form is the problem here. Actually, the path you’re using isn’t quite right. POSIX doesn’t use slashes in filenames; Their actually converted to colons.
I believe what you need to do is use POSIX path again. Try changing this line.
set destination to (AOLPosix & dataFol & "/")
.to this:
set destination to POSIX path of (AOLPosix & dataFol)
Here is my guess. The form of repeat that you are using returns a reference to the item in the list, not the item itself. Try replacing these two lines and see what happens:
set source to (AOLPosix & "Temp/" & (AOLLoc as Unicode text))
set destination to (AOLPosix & (dataFol as Unicode text) & "/")
If it still does not work, try rewriting the repeats in this form:
repeat with dataFol from 1 to count dataFolders
repeat with AOLLoc from 1 to count AOLLocations
set source to (AOLPosix & "Temp/" & (item AOLLoc of AOLLocations))
set destination to (AOLPosix & (item dataFol of dataFolders)& "/")
Thanks, guys! – but, unfortunately, neither of these appear to appease the scipting gods.
By using a simplified script, I can bypass the loops to narrow down the problem which really does seem to have to do with the slashes in the destination part of the command sent to ditto.
The simplified script:
tell application "Finder"
set AOLRef to a reference to folder ((name of startup disk) & ":Users:Shared:America Online:")
set AOLAlias to AOLRef as alias
set AOLPosix to POSIX path of AOLAlias
set dataFolders to the name of every folder in AOLRef whose name begins with "Data"
set AOLLocations to the name of every item in folder "Temp" of AOLRef
set AOLLoc to first item of AOLLocations
set dataFol to first item of dataFolders
set source to (AOLPosix & "Temp/" & AOLLoc)
set dest to (AOLPosix & dataFol & "/")
--do shell script
"ditto -rsrc " & quoted form of source & " " & quoted form of dest
end tell
Here, I’ve commented out the ‘do shell script’ part, so I can see what’s being fed to ditto. This one is still based on the original script.
Comparing the three versions – mine, and Craig’s and Bruce’s – they all produce the same output (save for a missing closing slash with Bruce’s):
Something is wrong with this picture, right? How is ditto supposed to know which slashes aren’t directories? I guess the slashes in the folder name need to be escaped somehow? Or can you quote the last folder name?
Something tells me there must be a must better way to do this?
set AOLFolder to alias ((path to startup disk as Unicode text) & "Users:Shared:America Online:")
tell application "Finder"
set dataFolders to the name of every folder in AOLFolder whose name begins with "Data"
set AOLLocations to the name of every item in folder "Temp" of AOLFolder
end tell
set AOLFolder to AOLFolder as Unicode text
repeat with thisDataFolder in dataFolders
repeat with thisLocation in AOLLocations
do shell script "ditto -rsrc " & ¬
quoted form of POSIX path of (AOLFolder & "Temp:" & thisLocation) & space & ¬
quoted form of POSIX path of (AOLFolder & thisDataFolder)
end repeat
end repeat