Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am writing some AppleScript in an Automator workflow, and I need to get the parent folder of a file (or folder) object. I have searched all over for this, and gotten the same answers, which are to use the "container", "parent", or "folder" properties. However, none of these work for me, whether or not they are wrapped in a 'tell "Finder"' block.

Thus, if I try something like:

set a to POSIX file "/usr/local"

tell application "Finder"
    set b to container of a
end tell

display alert a

I get the error message 'Can’t get container of file "Macintosh HD:usr:local".' The same thing happens with parent and folder.

Furthermore, if I do "display alert class of a", I get "furl". This is in AppleScript Editor. On the other hand, an Automator workflow with a Run Applescript module with the text

on run {input, parameters}
    repeat with i from 1 to length of input
        set the_file to item i of input
        display alert class of the_file
    end repeat
    return input
end run

displays "1634494835" in an alert box. But if I use "return class of the_file" instead, and use the View Results module, it shows the result as {alias}. Despite these strange class designations, I can use regular alias and file properties such as "POSIX path", with the file object.

Does anybody have any clue what's going on here? Is my AppleScript library broken or something?

share|improve this question
What exactly is the problem with the second part of your question? It seems to behave as intended...? – Daniel Beck Jan 8 '12 at 22:33
The number 1634494835 is the integer representation of the 'alis' OSType, which is what the OSType of the AppleScript alias class is. – NSGod Jan 10 '12 at 4:55

From the Library help of Standard Additions:

POSIX file n : A file object specified with a POSIX (slash)-style pathname.

  • POSIX path (text, r/o) : the POSIX (slash)-style path of a file or alias object

There is no container property.

You need what Finder considers an item to be able to do this. One way to get it:

set b to container of (a as alias)
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .