In AppleScript it’s possible to get the the POSIX path of the folder the current script is located in using this line:
POSIX path of ((path to me as text) & "::")
Example result: /Users/aaron/Git/test/
What’s the JavaScript equivalent?
In AppleScript it’s possible to get the the POSIX path of the folder the current script is located in using this line:
POSIX path of ((path to me as text) & "::")
Example result: /Users/aaron/Git/test/
What’s the JavaScript equivalent?
To complement the helpful existing answers by providing self-contained utility functions:
Note: These functions make use of the shortcut syntax forms for the ObjC bridge (
$(...)
forObjC.wrap()
and.js
forObjC.unwrap()
, and also take advantage of the fact that theFoundation
framework's symbols are available by default - see the OS X 10.10 JXA release notes.It's easy to generalize these functions to provide the equivalents of the POSIX
dirname
andbasename
utilities: