Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
1  
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
add comment

1 Answer

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.