Reveal in finder 不适用于连接的字符串

Reveal in finder does not work with concatenated string

为什么这样做:

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

如果我想将路径(字符串)与变量(字符串)连接起来,我该如何让它工作?

我建议使用相对 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

试试这个来组合字符串

reveal POSIX file (("/Users/Torben/Library/Mobile Documents/com~apple~CloudDocs/MyFolder/" & "file.png") as text)

系统事件 可以更好地处理 POSIX 路径,但这只是 AppleScript 的另一个怪癖。 POSIX file 将在 之外 Finder tell 语句工作:

set x to POSIX file (pathVariable & otherPathVariable)
tell application "Finder"
  activate
  reveal x
end tell

但是 一个 Finder tell 语句中,您需要将其用作强制:

tell application "Finder"
  activate
  reveal (pathVariable & otherPathVariable) as POSIX file
end tell