我如何在 JXA 中使用 POSIX 路径
How do I work with POSIX paths in JXA
在 AppleScript 中,我经常需要在作为 POSIX 路径和 AppleScript 的本机文件别名的文件之间进行转换。
方法是通过 POSIX 文件 class 在标准添加中:
set aFile to POSIX file "/"
get aFile's POSIX path
如何在 JXA 中执行这些 casts/conversions?我试过了
var app = Application.currentApplication();
app.includeStandardAdditions = true;
app.POSIXFile().make('/');
但我只得到
Error on line 4: Error: POSIXFile is not a valid class for application «Appname»
这就在documentation:
使用Path
:
var file = Path('/');
然后您可以在 AppleScript 允许的任何地方使用 file
。
虽然我仍然不知道标准添加的 POSIXFile
类型发生了什么(或者我需要如何称呼它)。
在 AppleScript 中,我经常需要在作为 POSIX 路径和 AppleScript 的本机文件别名的文件之间进行转换。
方法是通过 POSIX 文件 class 在标准添加中:
set aFile to POSIX file "/"
get aFile's POSIX path
如何在 JXA 中执行这些 casts/conversions?我试过了
var app = Application.currentApplication();
app.includeStandardAdditions = true;
app.POSIXFile().make('/');
但我只得到
Error on line 4: Error: POSIXFile is not a valid class for application «Appname»
这就在documentation:
使用Path
:
var file = Path('/');
然后您可以在 AppleScript 允许的任何地方使用 file
。
虽然我仍然不知道标准添加的 POSIXFile
类型发生了什么(或者我需要如何称呼它)。