Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get POSIX path of the current script's folder in JavaScript for Automation?

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?

like image 860
aaronk6 Avatar asked Feb 27 '15 19:02

aaronk6


1 Answers

Pure JXA code without ObjC involved:

App = Application.currentApplication()
App.includeStandardAdditions = true
SystemEvents = Application('System Events')

var pathToMe = App.pathTo(this)
var containerPOSIXPath = SystemEvents.files[pathToMe.toString()].container().posixPath()
like image 119
Puttin Avatar answered Nov 15 '22 10:11

Puttin