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

倾然丶 夕夏残阳落幕 提交于 2019-12-24 06:57:05

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/18525132/posix-path-in-applescript-from-list-not-opening-raw-path-works

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!