I’m trying to copy a file into a folder I create with a date stamp using POSIX paths. I’ve simplified the script substantially including setting everything to the HD to simplify the paths. The script works if I use Mac paths but can’t make it work using POSIX. This is the script
global dumm
tell application "Finder"
set TEST_Folder to POSIX file "/test"
set TEST_File to POSIX file "/test.txt"
set dumm to yymmdd() of me -- Run subroutine yymmdd() to generate date string
make new folder at TEST_Folder with properties {name:"PROFILE_" & dumm}
set PRO_Folder to POSIX file "/test" & "/PROFILE" & dumm
duplicate file TEST_File to PRO_Folder
end tell
I get the following error:
Can’t make {file "Bobs_PRO-1:test", "/PROFILE", "11-09-03"} into type folder."
I’ve been Googling for a few hours and trying many variations with no luck; even tried the AS Manual. As I said, this works fine
global dumm
tell application "Finder"
set dumm to yymmdd() of me -- Run subroutine yymmdd() to generate date string
make new folder at "Bobs_PRO-1:test:" with properties {name:"PROFILE_" & dumm}
duplicate file "Bobs_PRO-1:test.txt" to "Bobs_PRO-1:test:PROFILE_" & dumm
end tell
Model: Mac Pro running Lion
AppleScript: 2.4
Browser: Firefox 7.0
Operating System: Mac OS X (10.6)
set startupDisk to path to startup disk as text
set TEST_Folder to startupDisk & "test:"
set TEST_File to startupDisk & "test.txt"
set dumm to yymmdd() -- Run subroutine yymmdd() to generate date string
tell application "Finder"
set newFolder to make new folder at folder TEST_Folder with properties {name:"PROFILE_" & dumm}
duplicate file TEST_File to newFolder
end tell
I know there are numerous ways to do this using HFS paths. However, I was trying to figure out how to do it with POSIX paths. It seems like there should be a way.
At this point I view this as a challenge to be solved.
I agree with StefanK, using HFS paths is easy and the most efficient way. However I applaud you for being persistent and wanting to figure out why your script isn’t working. Here’s why…
the number one rule for everyone to learn is do not ask an application to perform a command it isn’t designed to perform. In your case that’s the “posix file” command. That is not a Finder command. “POSIX file” is an applescript command so do not ask the Finder to perform it. As you’re seeing when you ask the wrong application to perform a command you get errors. Look in the Finder’s applescript dictionary and you will not find the “posix file” command so that tells you that the Finder does not know the command. You will find that command in the dictionary of “StandardAdditions” which means it’s a native applescript command.
Your 2 lines here do not match, the second line is missing an underscore character after PROFILE…
make new folder at TEST_Folder with properties {name:"PROFILE_" & dumm}
set PRO_Folder to POSIX file "/test" & "/PROFILE" & dumm
In this line when you use “posix file” it only acts on the first variable “POSIX file “/test”” and not the “/PROFILE” part. You really want it to change all of the variables. As such you need parenthesis around them to indicate change all of them.
set PRO_Folder to POSIX file "/test" & "/PROFILE" & dumm
In your duplicate line you have the word “file” in front of the variable. The variable is already a posix file and thus the word “file” is not needed. You only need the word “file” when the variable is a string… your variable is not a string so the word is not needed.
As you can see your problem was that you made basic coding mistakes. There’s nothing wrong with the applescript language if you use it properly. Many times applescript is smart enough to fix some of these mistakes, so sometimes you can get away with making them. However you have 4 mistakes and applescript couldn’t overcome all of them. Here’s your script without any mistakes…
set TEST_Folder to POSIX file "/test"
set TEST_File to POSIX file "/test.txt"
set dumm to "110904" -- yymmdd()
tell application "Finder"
make new folder at TEST_Folder with properties {name:"PROFILE_" & dumm}
end tell
set PRO_Folder to POSIX file ("/test" & "/PROFILE_" & dumm)
tell application "Finder"
duplicate TEST_File to PRO_Folder
end tell
Thanks for the tutorial. As you may have guessed I don’t use AppleScript very often. Built about a dozen scripts way back under OS9 and have just evolved them.
With regard to the missing “_”, it wasn’t missing in the “real” script, I missed it when I “simplified the script substantially including setting everything to the HD to simplify the paths” when I posted here.
Again, thanks for your detailed explanation. I may just go with HFS as StefanK suggested.