AppleScript:显示带有变量的 POSIX 文件

AppleScript: Reveal POSIX file with variable

有人可以解释为什么这不起作用吗?

tell application "Finder"
   set myFile to "/Users/"
   reveal POSIX file myFile
end tell

此更改将起作用:

reveal myFile as POSIX file

奇怪的是,两个版本都没有变量:

reveal POSIX file "/Users/"
reveal "/Users/" as POSIX file

发生了什么事?

Matt Neuburg 写入

Do not confuse a coercion with an object string specifier! (See "Object String Specifier" in Chapter 11.)

This is a coercion: "feathers:" as alias

This is an object string specifier: alias "feathers:"

The distinction can be crucial. There are circumstances where the coercion will compile but the object specifier will not. You can't compile an alias specifier that uses a literal string unless the file exists, but you can compile a coercion from any string to an alias. And there are circumstances where the object string specifier will compile but the coercion will not. You can form a file specifier using a pathname string, but you can't coerce a string to a file object . (See "File Coercions," later in this chapter.)

或许可以从这里找到原因!