How to make folder inside folder on mounted volume?

Hi there! I’m new to Applescript and am about to shoot myself for not being able to figure this out. It’s probably just a pathway syntax, but I haven’t found ANY good documentation on how to write Applescripts, anywhere. So, I’ll have to ask the experts:

I’ve got a mounted folder called “Archives” which is a folder on a server that is automatically mounted upon startup.
I want to create a new folder called “T2008”, if it doesn’t already exist, on Archives.
I want to create a new folder called “070708” inside T2008 if it doesn’t already exist.
That’s it.

Thiis what I’m trying, but to no avail. The first half works, creating the T2008 folder, but fails at the second “make”, with:
“Finder got an error: Can’t get some object.”

set year_foldername to "T2008"
set new_foldername to "070707"
set arcfolder to "Archives" as alias

tell application "Finder"
	
	if (exists folder year_foldername of arcfolder) is false then
		make new folder at arcfolder with properties {name:year_foldername}
	end if
	if (exists folder new_foldername of folder year_foldername) is false then
		make new folder at year_foldername with properties {name:new_foldername}
		
	end if
end tell

Any help would be great. Thanks!

Here you go. You did not have a path to the newly created folder.


set year_foldername to "T2008"
set new_foldername to "070707"
set arcfolder to "Archives" as alias
set year_folder to arcfolder & year_foldername as string

tell application "Finder"
	
	if (exists folder year_foldername of arcfolder) is false then
		make new folder at arcfolder with properties {name:year_foldername}
	end if
	if (exists folder new_foldername of folder year_foldername) is false then
		make new folder at year_folder with properties {name:new_foldername}
	end if
end tell


Thanks, Craig, but now I get “Finder got an error: Can’t make class folder.” on that second “make” statement.
As you specified the missing pathway, “year_folder” - wouldn’t that concatenation end up with year_folder being “ArchivesT2008”?

try this

And no on the other question because you set “Archives” as an alias.


set year_foldername to "T2008"
set new_foldername to "070707"
set arcfolder to "Archives" as alias
set year_folder to arcfolder & year_foldername & ":" as string

tell application "Finder"
	
	if (exists folder year_foldername of arcfolder) is false then
		make new folder at arcfolder with properties {name:year_foldername}
	end if
	if (exists folder new_foldername of folder year_folder) is false then
		make new folder at year_folder with properties {name:new_foldername}
	end if
end tell

Hi,

a HFS path starts always with the name of the disk, even it is a shared volume (e.g. “theServer:Archives:”)
try this, it creates all intermediate folders silently

set year_foldername to "T2008"
set new_foldername to "070707"
set arcfolder to "theServer:Archives:"

do shell script "/bin/mkdir -p " & quoted form of (POSIX path of arcfolder & year_foldername & "/" & new_foldername)

Craig, I’m still getting the same message, “Can’t make class folder.” As Stefan mentioned, perhaps I need a more complete pathway name to the nested folder, so here is what it should be like:

MSN-Server.local/Archives/T2008/070707
I could also supply the “afp:// IP address” instead of the server name if that makes more sense.

If the “alias” part of defining “Archives” is throwing me/us off it’s because that was the only way I could make any of this work. I don’t even know what it means - I’ve just been trying bits and pieces from other people’s code because I can’t find documentation on how to build a good script. So, knowing that I REALLY don’t have a clue as to what I’m doing, what should this script actually look like?

Stefan, I have NO idea what you just came up with, as I have never seen even half of those words before…

It does exactly the same as Craig’s script,
if the name of the server is MSN-Server.local, the path is

set arcfolder to "MSN-Server:Archives:"

Sorry, Stefan, but nothing happens when I run this. Don’t I need some definition of what that shell script is? And what is a “quoted form” and “POSIX path”? Can you recommend a decent source for learning these things so I don’t have to bother you with these elementary questions?

I thank you for your time.

POSIX path is the UNIX representation of the path, which is needed for the shell script

the POSIX path of MSN-Server:Archives:T2008:070707: is /Volumes/MSN-Server/Archives/T2008/070707/

quoted form quotes the whole path to handle space characters in folder or file names correctly
I’ve tested my script above, it worked on my machine.
There are lots of good tutorials on MacScripter in unscripted

Hey sharkwood,

The first place to start learning is right here at MacScripter. The unScripted section at http://bbs.macscripter.net/viewforum.php?id=31 has lots of very useful information and great tutorials.

www.vtc.com has a very good video tutorial by Ben Waldie. I watched these several times when I first got started.

The book “AppleScript, The Comprehensive Guide to Scripting and Automation on Mac OS X” by Hanaan Rosenthal is the best book for beginners. Once you have learned a fair amount of AppleScript then read “AppleScript, The Definitive Guide” by Matt Neuburg.

As for your post. I am on Leopard and both scripts are working as expected. The way Stefan is doing it is the preferred way but most beginners, and some experienced AppleScripters as well, find shell scripting more intimidating.

There are lots of ways to accomplish the same task and it really boils down to a matter of preference.

Cheers,

Craig

Use this script to get the path of the “Archives” folder.
The results will be on your clipboard.


tell application "Finder"
	try
		set theSelection to a reference to the selection
	on error
		display dialog "You must have something selected." buttons {"OK"} default button 1
		error number -128
	end try
	set thePath to theSelection as alias
	set theChosenPath to button returned of (display dialog "HFS or POSIX." buttons {"POSIX", "HFS"} default button 2)
	if theChosenPath = "POSIX" then
		set thePOSIXpath to POSIX path of thePath
		set thePOSIXpath to "\"" & thePOSIXpath & "\""
		set the clipboard to thePOSIXpath
	else
		set thePath to "\"" & thePath & "\""
		set the clipboard to thePath
	end if
end tell

You are right, but in my experience a shell script works more reliably on a shared volume than the Finder

Craig & Stefan, thanks for your patience here!

I ran Stefan’s:

set year_foldername to "T2008"
set new_foldername to "070707"
set arcfolder to "MSN-Server:Archives:"

do shell script "/bin/mkdir -p " & quoted form of (POSIX path of arcfolder & year_foldername & "/" & new_foldername

and all that happened was a “” in the results window of the Scripter.

THEN, I checked out Craig’s “get file path” ditty and found that the path is: HFS = “Archives:”, POSIX = “/Volumes/Archives/”

SO, I substituted “Volumes” for “MSN-Server” in the arcfolder definition, and it worked! YAY!

THANK YOU THANK YOU THANK YOU!!!

Now, all I have to do is figure how to pass two variables from FileMaker Pro to substitute for year_foldername and new_foldername and I’ll be riding high. I’m a bit more up on my FM scripting than this Applescript stuff, so I might just get it figured out soon.
I thank you gentlemen again for you help, and I’ll read up on the sources provided by Craig.
Now, take the rest of the week off! :>)