Can't get the characters of this_folder

and it’s making me nuts. The reason I need the characters is because I will strip off the last folder in the path (in this case “:Inbox:”) and be left with the user folder. I will then pluck off the last folder name from the user folder and save it as the user name for the rest of my script. Unless I can SOMEHOW render the this_folder variable as a string or unicode text, which I have tried but failed to do, I am afraid I am at a stand still. Is this_folder some kind of special variable that won’t allow this kind of action?

on adding folder items to this_folder after receiving added_items
	tell application "Finder"
		activate
		set lBaseFolder to characters of this_folder as Unicode text

you can do either of the following

	set lBaseFolder to (this_folder as Unicode text)

Or if I’m reading you right you are just looking for the folders name? You can do this…

	set lBaseFolder to name of this_folder

Not quite; Consider this:

try
	choose folder
	characters of result as Unicode text -- errors
on error errMsg
	return errMsg
end try

You should something like this as the result:

Read that. Again. Now, read it like this:

  • characters of alias “whatever”
  • Unicode text

Now, try this:

try
	choose folder
	characters of (result as Unicode text) -- works
on error errMsg
	return errMsg
end try

That said, I don’t know why you’re using characters to do this. Any of these should work:

choose folder
set thisFolder to result

set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set baseFolder to text item -3 of (thisFolder as Unicode text)
set AppleScript's text item delimiters to ASTID

baseFolder
choose folder
set thisFolder to result

tell application "Finder" to set baseFolder to name of container of thisFolder
choose folder
set thisFolder to result

tell application "System Events" to set baseFolder to name of container of thisFolder

Hmmmm. :confused: :smiley:

Well, I will tell you why Bruce, but you’re going to laugh. Perhaps in amusement, perhaps derisively, but the following code is what I was attempting:


			set lBaseFolder to name of this_folder
			set lBaseFolder to characters of lBaseFolder
			set lStartPoint to ""
			set x to -2 --Last character of path is always a colon, must set to 2nd from last
			repeat until lStartPoint is ":"
				set x to x - 1 -- Count backwards until next colon is found
				set lStartPoint to item x of lBaseFolder
			end repeat
			set lStrippedName to items 1 thru x of lBaseFolder
			set lUserFolder to lStrippedName as Unicode text

Since I am new to Applescript I lack a certain, oh, let’s call it ability. I could however see immediately that your solutions were ALL far more elegant where mine are hideously contorted. Like a three legged stray wrapped around a tree, with mange, and on fire. Dogs can explode on impact, it’s true.

James, Bruce, I appreciate the help. It is nice to know that there are good people out there willing to help the mentally disabled. Now I’m going to strap my helmet back on, use your recommendations, and fix this script.

I may be missing something here (at my age it happens with increasing frequency), but you seem to be pursuing the names of container(s) of a file. This illustrates how to get them.


set myPath to (path to preferences folder from user domain)
tell application "Finder"
	set PF to files of myPath as alias list
	set RF to item 10 of PF
	-- gets us a path to some file in your users preferences folder.
	-- Now:
	set RFC to (container of RF as alias)
	set RFCN to name of RFC -- "Preferences"
	set RFCC to (container of container of RF as alias)
	set RFCCN to name of RFCC -- "Library"
	-- etc.
end tell

-- Alternatively go after it from the text:

set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set tPathNames to text items of (RF as string)
set AppleScript's text item delimiters to tid
reverse of tPathNames -- a list. first item is file, item 2 is its container, etc.

Adam,

What I am attempting to do is this:

I set up a user in PureFTPd Manager, in effect creating an FTP account for them on my Mac, this results in a folder being created for the user in my FTP directory on an external HD. The user folder (call it John) triggers a script attached to the FTP directory folder which duplicates an Inbox and an Outbox folder to John and then attaches an Inbox.scpt and an Outbox.scpt to the respective folders. So far this all works perfectly

The following portion of script is from the Inbox.scpt where I am trying to set gUserFolder to the user folder path that the files are dropped into (ie"MAC ESD:FTP Server::Inbox:“) but minus the “Inbox:”. I want the gFTPFolder to then be set to gUserFolder (ie"MAC ESD:FTP Server::”) just minus the “:”. I was then going to try to grab the name of gUserFolder to use as the user name in gUserName, so just “:”.

This doesn’t even touch on the XML parsing, reading text into variables, and the automatic email notification system that tie into the Inbox script with the loading of scripts and the passing of parameters… If I actually stop long enough to think about this I would probably just save myself the headaches and the growing suspicion that I’m not up to the task and give up. But I REALLY want to learn this.

global gFTPFolder, gUserFolder, gDMTFolder, gUserName

on adding folder items to this_folder after receiving added_items
	tell application "Finder"
		activate
		try
			set z to 1 -- Block marker
			tell application "System Events" to set gUserFolder to (path of (container of (this_folder as alias)))
			set gUserFolder to (gUserFolder as Unicode text) -- Base user folder
			display dialog gUserFolder
			set gFTPFolder to alias (this_folder as Unicode text) -- Inbox of user folder
			display dialog gFTPFolder
			set lApplicationsFolder to ((path to applications folder) as Unicode text)
			set gDMTFolder to (lApplicationsFolder & "Design-Mo-Tron:" as Unicode text)
			set lScriptsFolder to (gDMTFolder & "Components:Scripts:" as Unicode text)
			
			--> Wait for client files to finish uploading
			
			set z to 2 -- Block marker
			repeat
				set x to (info for gUserFolder with size)
				delay 1
				set y to (info for gUserFolder with size)
				if x = y then exit repeat
			end repeat
		on error msg
			display dialog "Error in block " & z & ": " & msg with icon stop
		end try
	end tell
end adding folder items to

Am I even on the right track? I tried to use what Bruce, James, and yourself suggested but I couldn’t figure out how to make it work. The above result is my fevered attempt to twist it into a working script.

Give this a try

global gFTPFolder, gUserFolder, gDMTFolder, gUserName

on adding folder items to this_folder after receiving added_items
	tell application "Finder"
		activate
		try
			set z to 1 -- Block marker
			tell application "System Events" to set gUserFolder to path of container of this_folder
			display dialog gUserFolder
			set gFTPFolder to this_folder as Unicode text -- Inbox of user folder
			display dialog gFTPFolder
			set lApplicationsFolder to (path to applications folder) as Unicode text
			set gDMTFolder to (lApplicationsFolder & "Design-Mo-Tron:" as Unicode text)
			set lScriptsFolder to (gDMTFolder & "Components:Scripts:" as Unicode text)
			
			--> Wait for client files to finish uploading
			
			set z to 2 -- Block marker
			repeat
				set x to size of folder gUserFolder
				delay 1
				set y to size of folder gUserFolder
				if x = y then exit repeat
			end repeat
		on error msg
			display dialog "Error in block " & z & ": " & msg with icon stop
		end try
	end tell
end adding folder items to

Thanks James,

That seems to have cleared up the issues with the folder paths but now instead of the ‘Error in block 2: Finder got an error: File ESD MAC:FTP Server:Johnny Test: wasn’t found’ with my code (see below)-

My Code:

           repeat
               set x to (info for gUserFolder with size)
               delay 1
               set y to (info for gUserFolder with size)
               if x = y then exit repeat
           end repeat

The script is continuing on and not waiting for the files to finish copying with yours.

Your Code:

           repeat
               set x to size of folder gUserFolder
               delay 1
               set y to size of folder gUserFolder
               if x = y then exit repeat
           end repeat

Is there a qualitative difference between the info size and the folder size? Aren’t they the same thing? Could I maybe use the Busy Status for this like:

repeat
    if busy status of folder gUserFolder is false then exit repeat
    delay 1
end repeat

…apparently not. See this is what I find so confusing, to me it ALL looks like it should work.

It should be the same thing but it isn’t.
For folders with a hugh amount of subfolders it takes some time to calculate the size.
the info for command results a missing value , while the Finder waits a moment.
The most robust version is:


tell application "Finder"
	set s to missing value
	repeat while s is missing value
		set s to size of (path to library folder)
		delay 0.5
	end repeat
end tell

No, the busy status indicates something else

Interesting, I actually didn’t know this. =)

@ Rectal - nice to see you using Pure btw… I run our companys man FTP box using Pure.

Stefan,

I used your code and am getting a 'Error in block 2: Can’t get the size of “ESD MAC:FTP Server:Test User:Inbox”. Now the files I am expecting to be dropped in the inbox probably won’t have a large number of subfolders but will have a large number of miscellaneous files (graphics, movie clips, excel documents, etc.), and that is what I am testing with… Could that be what is affecting the repeat loop? BTW - I changed the variable name gFTPFolder to gInboxFolder because it is more accurate in describing the function of the folder.

global gUserFolder, gInboxFolder, gDMTFolder, gUserName
local lApplicationsFolder, lScriptsFolder, lJobType, lUserName, lAddress, lCity, lState, lZipCode, lXMLFileName

on adding folder items to this_folder after receiving added_items
	tell application "Finder"
		activate
		try
			set z to 1 -- Block marker
			tell application "System Events" to set gUserFolder to path of container of this_folder
			set gInboxFolder to this_folder as Unicode text -- Inbox of user folder
			set lApplicationsFolder to (path to applications folder) as Unicode text
			set gDMTFolder to (lApplicationsFolder & "Design-Mo-Tron:" as Unicode text)
			set lScriptsFolder to (gDMTFolder & "Components:Scripts:" as Unicode text)
			
			--> Wait for client files to finish uploading
			
			set z to 2 -- Block marker
			set s to missing value
			repeat while s is missing value
				set s to size of gInboxFolder
				delay 1
			end repeat
                        on error msg
			display dialog "Error in block " & z & ": " & msg with icon stop
		end try
	end tell
end adding folder items to

James,

I found PureFTP when a group of friends I used to LAN game with were complaining about not being able to move large files through e-mail and not wanting to do it through apps like MSN Messenger (why I don’t know - I don’t IM). I set it up, got a DYNDNS account and in less than a day had a system they could use. I also tried Zimbra but not so much luck with that. The installation via the terminal had me completely confused, who would have guessed what with MY razor sharp intellect and all? :rolleyes:

LOL no one likes the finder anyways and info for had been ruled out. I say go back to a comparison, but using

set s to do shell script "/usr/bin/du " & quoted form of (POSIX path of gInboxFolder) & space & "| /usr/bin/awk '{print $1}'"

Hi Rectal Exam-bot,

What you need to do is learn about references. Basically you’re getting errors because you’re using strings (path to the file or folder) and not references. There are three main types of references: Finder reference, allias reference, and file specification. this_folder is an alias reference. When you get the ‘container’ property, it returns a Finder reference. Coercing both of these to unicode text returns text and not reference. If you’re using the Finder to get the size, you can keep your Finder reference and use that. You can also coerce the Finder reference to alias reference with ‘as alias’. You do this when you want to use the reference outside the Finder.

Many beginning scripters have been confused by this (references) and it takes getting used to. Just remember, text are not references.

gl,

:frowning: Aw hell James, I can’t figure out Applescript and now you’re throwing Unix at me?!? I actually have ‘Unix in 10 minutes’ sitting on my desk in case I ever DO manage to get Applescript but come on… I can’t even figure out how to get a path, a simple little path, in a form that I can manipulate. There is a better chance that Zeus will come to me in a dream and teach me to think in machine code. I will take the code you gave me but I don’t want to use it if I don’t understand it. Thats just cheating. :smiley:

Kel, I have been fighting with these references for a while now for example:

set gInboxFolder to (this_folder as Unicode text) -- Inbox of user folder
			tell application "System Events" to set gUserFolder to path of container of (this_folder as Unicode text)
			tell application "System Events" to set gFTPFolder to path of container of (gUserFolder as Unicode text)
			set lApplicationsFolder to ((path to applications folder) as Unicode text)
			set gDMTFolder to (lApplicationsFolder & "Design-Mo-Tron:" as Unicode text)
			set lScriptsFolder to (gDMTFolder & "Components:Scripts:" as Unicode text)

to my way of thinking this should work - this_folder is being coerced into unicode text as are all of the paths, but it doesn’t. What I get is the error "Error in block 1: Can’t get <> of “ESD MAC:FTP Server:Test User: Inbox:”. that points to a problem in this line:

set gInboxFolder to (this_folder as Unicode text) -- Inbox of user folder

But I asked Applescript to coerce this_folder into unicode text right? I read it to say “set variable to path as unicode text” but it obviously isn’t doing it. This is about as simple as my paths get and it’s not working so what am I missing? If I remove the braces the error is exactly the same so it doesn’t appear to be a matter of precedence, GAHHHHHHH! I’m going to bed now. I jut can’t fight with this stuff one more minute.

→ I’m so tired I only now realized that the above line:

set gInboxFolder to (this_folder as Unicode text) -- Inbox of user folder

should have been:

tell application "System Events" to set gUserFolder to path of container of (this_folder as Unicode text)

Say goodnight Gracie…

Give this a try

set gInboxFolder to (this_folder as Unicode text) -- Inbox of user folder
tell application "Finder"
	set gUserFolder to (container of this_folder)
	set gFTPFolder to (container of gUserFolder)
end tell
set lApplicationsFolder to (path to applications folder) as Unicode text
set gDMTFolder to (lApplicationsFolder & "Design-Mo-Tron:")
set lScriptsFolder to (gDMTFolder & "Components:Scripts:")

Note that gUserFolder ang gFTPFolder are still “containers”. I generally don’t coerce items until needed. Also I switched to the finder becauase I had experiecnced problems coercing System Event returned containers.

Hope that helps somewhat =)

Well here is what finally worked:

global gFTPFolder, gUserFolder, gInboxFolder, gDMTFolder, gUserName
local lApplicationsFolder, lScriptsFolder, lJobType, lUserName, lAddress, lCity, lState, lZipCode, lXMLFileName

on adding folder items to this_folder after receiving added_items
	tell application "Finder"
		activate
		try
			set z to 1 -- Block marker
			set gInboxFolder to (this_folder as Unicode text) -- Inbox of user folder 
			set gUserFolder to ((container of folder gInboxFolder) as Unicode text) -- User folder
			set gFTPFolder to ((container of folder gUserFolder) as Unicode text) -- Base FTP folder
			set lApplicationsFolder to ((path to applications folder) as Unicode text) -- Applications folder
			set gDMTFolder to (lApplicationsFolder & "Design-Mo-Tron:" as Unicode text) -- DMT application folder
			set lScriptsFolder to (gDMTFolder & "Components:Scripts:" as Unicode text) -- Scripts folder inside DMT folder
			
			--> Wait for client files to finish uploading
			
			set z to 2 -- Block marker
			repeat
				set x to (info for alias gInboxFolder with size)
				delay 1
				set y to (info for alias gInboxFolder with size)
				if x = y then exit repeat
			end repeat
		on error msg
			display dialog "Error in block " & z & ": " & msg with icon stop
		end try
	end tell
end adding folder items to

I had to revert back to my original repeat loop (with slight modification), dumped “System Events” as James recommended (even though he was the one who put me onto it in the first place :confused: - 2007-05-23 02:15:55), and added ‘folder’ between ‘container of’ and ‘my variable’. I’m still not entirely sure why this worked and all of the rest failed, but I’ve got NEW errors, XML errors to deal with ! I am almost giddy to be failing upward for a change.