Trying to define and generate folder hierarchy

Hi All,

Please go easy on me as this is my first post:

I am trying to write a script to generate a folder hierarchy automatically. (My OS Version 10.4.11)
(Ultimately I want this to become a discreet module that can be passed parameters and used by other higher level modules so I don’t have to worry about the working details every time.)

For now though, I am having real difficulties even capturing and using references to folders/finder items. On searching google I found the following thread which looks to be the sort of thing I am after:

http://forums.macosxhints.com/archive/index.php/t-70505.html

The following method looks interesting but unfortunately doesn’t seem to work:


set theLocation to <alias of path to where you want the folder> --this was replaced with path to desktop as alias
tell application "Finder"
set archiveFolder to make new folder at theLocation with properties {name:"ARCHIVE"}
set assetsFolder to make new folder at archiveFolder with properties {name:"ASSETS"} --script fails on this line: -->Finder Can't get some object
set FPOFolder to make new folder at assetsFolder with properties {name:"FPO Images"}
set HiResFolder to make new folder at assetsFolder with properties {name:"Hi-Res Images"}
set illustratorFolder to make new folder at assetsFolder with properties {name:"Illustrator Assets"}
set logoFolder to make new folder at assetsFolder with properties {name:"Logos"}
set copyFolder to make new folder at archiveFolder with properties {name:"Copy"}
set layoutFolder to make new folder at archiveFolder with properties {name:"LAYOUTS"}
set setFolder to make new folder at archiveFolder with properties {name:"OK TO SET", label index:2}
set pdfFolder to make new folder at archiveFolder with properties {name:"PDF"}
end tell:

On studying the event log, it seems that the chain of "of"s seems to be clipped, i.e the path only extends to the current user folder, and cuts off there:
e.g. archiveFolder becomes: folder “ARCHIVE” of folder “Desktop” of item “”…no more path.

I’ve been reading Applescript the Definitive Guide, and Applescript The Comprehensive Guide to Scripting… I still can’t seem to find the correct way to do this sort of thing though…

Can anyone elucidate this one for me?

Thanks in advance for replies, it’s driving me mad!!!

Hi,

your sample script works fine on my machine.
If you don’t need all these variable names of the folders, this way is the most elegant one

set theLocation to path to desktop -- as alias is useless, because "path to" returns an alias
do shell script "/bin/mkdir -p " & quoted form of POSIX path of theLocation & "Archive/{Copy,LAYOUTS,OK\\ TO\\ SET,PDF,ASSETS/{FPO\\ Images,Hi-Res\\ Images,Illustrator\\ Assets,Logos}}"
tell application "Finder" to set label index of folder ((theLocation as text) & "Archive:OK TO SET:") to 2

Here’s a little more flexible method:

set folderlist to {"ARCHIVE", "ASSETS", "FPO Images", "Hi-Res Images", "Illustrator Assets", "Logos", "Copy", "LAYOUTS", "OK TO SET", "PDF"}
set labellist to {0, 0, 0, 0, 0, 0, 0, 0, 3, 0}
set pos to {0, 1, 2, 2, 2, 2, 1, 1, 1, 1}
tell application "Finder"
	set theLocation to path to desktop folder as text
	set foldercount to count of items in pos
	repeat with foldernumber from 1 to foldercount
		set labelp to item foldernumber of labellist
		set x to item foldernumber of pos
		set y to ""
		if x > 0 then
			repeat with i from 1 to x
				set y to y & item i of folderlist & ":"
			end repeat
		end if
		set newlocation to theLocation & y as alias
		set newfolder to item foldernumber of folderlist
		make new folder at newlocation with properties {name:newfolder}
		set label index of folder ((newlocation as text) & newfolder) to labelp
	end repeat
end tell

You can change relative positions of some of the folders and their labels by manipulating their lists.