3

In AppleScript I often need to convert between files as POSIX paths and as AppleScript’s native file aliases.

The way to do it is via the POSIX File class in standard additions:

set aFile to POSIX file "/"
get aFile's POSIX path

How do I do these casts/conversions in JXA? I’ve tried

var app = Application.currentApplication();
app.includeStandardAdditions = true;

app.POSIXFile().make('/');

But I only get

Error on line 4: Error: POSIXFile is not a valid class for application «Appname»

Raphael Schweikert
  • 18,244
  • 6
  • 55
  • 75

1 Answers1

3

This is right in the documentation:

Use Path:

var file = Path('/');

And then you can use file anywhere file references would be allowed in AppleScript.

Though I still don’t know what happened to the POSIXFile type from the standard additions (or how I’d need to call it).

Raphael Schweikert
  • 18,244
  • 6
  • 55
  • 75