简体   繁体   中英

POSIX path in applescript from list not opening. Raw path works

I'm really confused with this one. All I want is the files in the list to open. Here's my codes

set FilesList to {"Users/XXXXXX/Documents/07PictureArt-Related/THINGS THAT HELP/Tutorials/artNotesfromFeng.rtf", "Users/XXXXXXXX/Documents/07PictureArt-Related/THINGS THAT HELP"}

repeat with theFiles in FilesList
    delay 0.1
    tell application "Finder" to open POSIX file (theFiles)
end repeat

So, how come THAT won't work, but this will???

tell application "Finder" to open POSIX file "Users/XXXXXX/Documents/07PictureArt-Related/THINGS THAT HELP/Tutorials/artNotesfromFeng.rtf"

I'm thinking it might have to do with maybe the list is making it a string, and when I plug it directly into the open command, it LOOKS like a string, but it's not really...I don't know

For now I guess I just have to brute force it, and make a new statement for each file.

Thanks

Not sure what is going on there, i agree it's confusing.

An alternate is to use the shell 'open' command instead.

repeat with filePath in FilesList
    do shell script "open " & quoted form of filePath
end repeat

The shell seems more happy with POSIX paths, the trick is to send in the 'quoted form' of your POSIX paths.

-- EDIT: Putting into a var first works too.

repeat with theFiles in FilesList
    set f to POSIX file theFiles
    tell application "Finder" to open f
end repeat

It seems the Finder is causing the coercion to POSIX file problem.

Either of these works:

set l to {"/bin", "/etc"}
repeat with f in l
    tell application "Finder" to open (POSIX file (contents of f) as alias)
end repeat
set l to {"/bin", "/etc"}
repeat with f in l
    POSIX file f
    tell application "Finder" to open result
end repeat

Try running this script:

set l to {"/bin", "/etc"}
repeat with f in l
    f
end repeat

The result at the end is item 2 of {"/bin", "/etc"} . contents of returns the target of the reference object.

I don't know why POSIX file f doesn't work inside a tell application "Finder" block, or why POSIX file f as alias does work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM