首页 > 解决方案 > 在查找器中显示不适用于连接字符串

问题描述

为什么会这样:

tell application "Finder"
    activate
    reveal POSIX file ("/Users/Torben/Library/Mobile Documents/com~apple~CloudDocs/MyFolder/file.png")
end tell

...但不是这个

tell application "Finder"
    activate
    reveal POSIX file ("/Users/Torben/Library/Mobile Documents/com~apple~CloudDocs/MyFolder/" & "file.png")
end tell

如果我想用变量(字符串)加入路径(字符串),我该如何让它工作?

标签: applescript

解决方案


我建议使用相对 HFS 路径。第一行指向library当前用户的文件夹。

set libraryFolder to path to library folder from user domain as text
tell application "Finder"
    reveal file (libraryFolder & "com~apple~CloudDocs:MyFolder:" & "file.png")
end tell

推荐阅读