在查找器中显示不适用于串联字符串

时间:2019-03-21 11:34:32

标签: applescript

为什么这样做:

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

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

3 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

尝试将其组合成字符串

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

答案 2 :(得分:0)

系统事件处理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