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 currently using this UNIX shell command in my script file:

do shell script "open ~/Dropbox/Media/VisionBoard/*"

Is there another way to do it and if so would it be any better or different? I'm still new to programming, so please be gentle.

share|improve this question

1 Answer 1

up vote 4 down vote accepted
tell application "Finder"
    set myFolder to ((home as text) & "Dropbox:Media:VisionBoard") as alias
    set myFiles to (every item of myFolder) as alias list
    open myFiles
end tell

Instead of "every item" you can also say "every file" or "every folder".

share|improve this answer
    
What's the significance of "as alias," and is that why we can't say open every item of ((home as text) & "Dropbox:Media:VisionBoard")? –  NReilingh Aug 12 '10 at 18:42
    
I am no AppleScript guru, just a student. There may be many ways to do it. From Apple's AppleScript Language Guide: “An alias object is a dynamic reference to an existing file system object. [...] The following is the recommended usage for these types: * Use an alias object to refer to existing file system objects. * Use a file object to refer to a file that does not yet exist.” developer.apple.com/mac/library/documentation/AppleScript/… –  ischeriad Aug 12 '10 at 19:18
3  
@NReilingh By default, Applescript treats the bracketed term as a string. The every keyword specifies every object in a container. Strings contain characters. If you try and open every item of a string, AppleScript will throw an error because it can't convert the characters into type item. Items in the Finder are files, folders, etc. Therefore you coerce the file path string to an alias, which is a reference to an existing file, folder, or volume in the file system. The Finder can then treat that alias as a container of file system items. –  ghoppe Aug 12 '10 at 19:52
    
Thanks for the discussion. It gave me some great insights as to how AppleScript works. The information is probably of no tangible use, but can anyone confirm my suspicion that running pure AppleScript is more efficient than using it to perform a shell script? –  Orion751 Aug 13 '10 at 18:59

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.