File and Folder reference problems

I apologize for being so dense but I just am not seeing something critical about file and folder references in Applescript. Every time I try to do something I run into the same problems simply referencing them. Although this appears to be similar to what I do in other scripts, it apparenlty is just enough different that my interpritation of the syntax needed is flawed. The following code tells me it cannot find the folder referenced by ‘f_item’. Since it got the folder name in the first place why can’t it find it in the 2nd?


set homes to "USER1:Users-home:"
tell Application "Finder"
   set home_folders to folders of (alias homes)
   repeat with f_item in home_folders
      set folder_info to info of folder f_item
      display dialog folder_info as string
   end repeat
end tell

If I understand it (which I apparently don’t) the use of ‘alias’ effectively converts the internal respresentation into a string (not sure what the difference between that and ‘as string’ is) while not using alias leaves it in some internal format. I don’t seem to have a clue when to use which. TIA.

What are you expecting ‘set folder_info to info of folder f_item’ to return?

– Rob

The Finder uses its own file references (hierarchical references), such as:

folder "x" of folder "y" of startup disk of application "Finder"

“File specifications” are:

file "path:to:file"

“Aliases” are:

alias "path:to:file"

POSIX paths are:

"/to/file"

And simple paths:

"path:to:file"

Usually, the best way to reference a file or folder is “alias”, since most of applications will accept and understand it.

In your code, “f_item” is a Finder file reference (folder “x” of folder “y” of…). And the command “info for” (not “info of”) of the Standard Additions will not accept as valid such reference. You must create a “path”, “file specification” or “alias” reference.
For example:

set folder_info to info for alias (f_item as text)
  • Of course, you can’t coerce “folder_info” to text. It is a record.

Thanks, that did the trick. This is still very fuzzy to me. I did try using alias but that got an error that it could not covert the data to the appropriate type. I never used ‘as text’ before. Is that the same as ‘as string’?

I have, appropriately, “Applescript for Dummies,” but I can’t get anything in it to work as avertised.

Yep… “text” and “string” is the same… There are some confusing concepts for beginners in AS, such as a great amount of file specifications, lots of kinds of text (string, text, unicode text, international text, etc.)… I hope in a future Apple will unify all data types and keep only “alias” (or “file” or whatever) and “text” (or “Unicode text” or whatever)…