The case of the unruly variable

Okay, First off my Name is Eric and I am an Applescripting NOOB. Not that I am completely clueless when it comes to scripting (Lingo, Actionscript, JavaScript) but this is my first crack at Applescript.

Below is the portion of the script that is causing me the problem, which is that I get the error “Finder got an error: Can’t make class folder.” when the line

make new folder at gCustomerFolder with properties {name:lBox}

attempts to run. The problem seems to be with the variable gCustomerFolder which I eventually deduced by:

  1. putting the location desktop in place of the variable and
  2. typing in the full path “ESD MAC:FTP Server:Company A:” in place of the variable

Both of which resulted in the script performing successfully. I had also tried to use the alias form of the variable and attached the disk using it’s firewire and then it’s USB cable none of which did anything.

What is the problem I am having here? Why wont the variable gCustomerFolder, which has the very same information associated with it as the typed path “ESD MAC:FTP Server:Company A:”, have the same result when the script is run? I want to avoid hard coding the disk and folder paths at all costs so any help would be greatly appreciated.

global gMainHD, gFTPFolder, gCustomerFolder, gScriptsFolder

tell application "Finder"
	activate
	set gMainHD to startup disk as string
	set gCustomerFolder to (choose folder with prompt "Select the Users FTP Folder") as string
	set gScriptsFolder to "Backups_MAC & PC:Mac:My Automation:Applescripts:" --Hardcoded path (Fix this)
	set lInboxScripts to {"eMail.scpt", "DBase.scpt", "iCal.scpt", "imaging.scpt", "Decider.scpt"} --Rewrite to set to contents of folder A
	set lOutboxScripts to {"DBase.scpt", "iCal.scpt", "Cleanup.scpt", "eMail.scpt"} --Rewrite to set to contents of folder B
	set lCFCharacters to characters of gCustomerFolder
	set lStartPoint to ""
	set x to -2 --Last character is always a colon, must set to 2nd from last
	
	repeat until lStartPoint is ":"
		set x to x - 1 --Go backwards until a colon is found
		set lStartPoint to item x of lCFCharacters
	end repeat
	
	set gFTPFolder to items 1 thru x of lCFCharacters as string --Strip customer name from gCustomerFolder
	my sMakeFolder("Inbox", lInboxScripts)
	my sMakeFolder("Outbox", lOutboxScripts)
end tell

on sMakeFolder(lBox, lBoxScripts)
--set y to count of lBoxScripts
	tell application "Finder"
		make new folder at gCustomerFolder with properties {name:lBox}
--repeat with i from 1 to y
--attach action to folder gCustomerFolder & lBox using gScriptsFolder and name
--end repeat
	end tell
end sMakeFolder

Model: Mac Mini - PPC
AppleScript: 10.4.9
Operating System: Mac OS X (10.4)

Hi Eric,

the problem is, your variable gCustomerFolder is a string, but should be a file specifier or an alias.
Try this, to get the parent folder of the chosen folder can also be done easier

global gMainHD, gFTPFolder, gCustomerFolder, gScriptsFolder

set gMainHD to startup disk as string
set gCustomerFolder to (choose folder with prompt "Select the Users FTP Folder")
set gScriptsFolder to "Backups_MAC & PC:Mac:My Automation:Applescripts:" --Hardcoded path (Fix this)
set lInboxScripts to {"eMail.scpt", "DBase.scpt", "iCal.scpt", "imaging.scpt", "Decider.scpt"} --Rewrite to set to contents of folder A
set lOutboxScripts to {"DBase.scpt", "iCal.scpt", "Cleanup.scpt", "eMail.scpt"} --Rewrite to set to contents of folder B
tell application "Finder" to set gFTPFolder to container of gCustomerFolder as Unicode text

sMakeFolder("Inbox", lInboxScripts)
sMakeFolder("Outbox", lOutboxScripts)


on sMakeFolder(lBox, lBoxScripts)
	--set y to count of lBoxScripts
	tell application "Finder"
		make new folder at gCustomerFolder with properties {name:lBox}
		--repeat with i from 1 to y
		--attach action to folder gCustomerFolder & lBox using gScriptsFolder and name
		--end repeat
	end tell
end sMakeFolder

PS: I recommend to add a message, whether the gCustomerFolder already exists

:DThank you Stefan. I used your suggestion and modified it a bit and it works like a charm. Now just to be clear: if the variable result is the path to something it should be ‘as unicode text’ instead of ‘as string’?

Now I am off to fix the ‘duplicate name’ error message when I try to attach an applescript to the folders… if it aint one thing it’s another!

It makes actually no difference in this case (AppleScript is indeed very liberal),
but the native text class of file names and paths is Unicode text, so I’m using it always

PS: attach action is a term of System Events, not of the Finder :wink:

:smiley: Today must be my day! Seconds after I posted my kvetch about the ‘duplicate name’ error I figured out where I was screwing up. ZAM! Now to begin the heavy lifting… I’ve got at least a dozen ugly hairy scripts to write before I’m done.