I just know I’m going to feel really stupid when someone points out what I’m missing, but what the heck. I’m running the following script which duplicates the file ‘pone.png’ from my Desktop dir into a Desktop/temp directory.
tell application "Finder"
tell application "Finder" to get home
set fileName to "pone.png"
set tmpDir to "temp:"
set filePath to quoted form of POSIX path of ("Saber:" & (home as text) & ":sss:Desktop:" & fileName)
set destPath to quoted form of POSIX path of ("Saber:" & (home as text) & ":sss:Desktop:" & tmpDir)
duplicate file filePath to folder destPath with replacing
(*duplicate file "Saber:Users:sss:Desktop:pone.png" to folder "Saber:Users:sss:Desktop:temp:" with replacing*)
end tell
When I run it, I get :
Commenting out the first ‘duplicate file’ line and uncommenting the second (with the quoted string) works just fine.
Why does get home point to my /Users directory instead of my /Users/sss directory?
This shell script should move a copy of the ‘pone.png’ file into the ‘temp’ folder with replacing…
do shell script "/bin/cp ~/Desktop/pone.png ~/Desktop/temp"
or you could try this…
tell application "Finder"
set home_path to home as text
set source to alias (home_path & "Desktop:pone.png")
set destination to home_path & "Desktop:temp:"
tell application "Finder" to duplicate source to destination with replacing
end tell
AppleScript works with HFS paths (colon separated), POSIX paths don’t work
As the desktop folder is the “root” folder of the Finder, this is sufficient
tell application "Finder" to duplicate file "pone.png" to folder "temp" with replacing
To specify the desktop the dictionary has a desktop property
tell application "Finder"
desktop as text --> "MacHD:Users:myUser:Desktop:"
end tell
Many, many thanks. I really appreciate the explanations and both solutions work very well, though I’ll probably stick with Tom’s, just b/c I don’t know for sure where the files will eventually live and it gives me a little more flexibility.