# Receive project path in macOS from Lua (SOLVED)

**URL:** <https://forum.defold.com/t/receive-project-path-in-macos-from-lua-solved/13375>\
**Category:** Questions\
**Created:** [November 5, 2017, 11:48pm UTC](https://forum.defold.com/t/receive-project-path-in-macos-from-lua-solved/13375 "2017-11-05T23:48:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![tarnumius](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@tarnumius](https://forum.defold.com/u/tarnumius)\
**Post date:** [November 5, 2017, 11:48pm UTC](https://forum.defold.com/t/receive-project-path-in-macos-from-lua-solved/13375/1 "2017-11-05T23:48:51Z")

</div>

Hi all.

In my project I recieve some data from external files. In Windows project read files from application dir by default, but in macOS no and required absolute path. My question - how recieve current dir in macOS. I know about os.getenv(“HOME”) , but it return user home, but i need app dir. Thank you

---

<div class="post-metadata">

**Author:** ![Pkeod](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pkeod/32/606_2.png) [@Pkeod](https://forum.defold.com/u/Pkeod)\
**Post date:** [November 6, 2017, 12:23am UTC](https://forum.defold.com/t/receive-project-path-in-macos-from-lua-solved/13375/2 "2017-11-06T00:23:51Z")

</div>

What do you need app dir for? You shouldn’t write to the application directory but to user data folders.

---

<div class="post-metadata">

**Author:** ![tarnumius](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@tarnumius](https://forum.defold.com/u/tarnumius)\
**Post date:** [November 6, 2017, 12:27am UTC](https://forum.defold.com/t/receive-project-path-in-macos-from-lua-solved/13375/3 "2017-11-06T00:27:01Z")

</div>

I need read some PNG files (long animation sequences). I dont need write for current moment 🙂

---

<div class="post-metadata">

**Author:** ![Pkeod](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pkeod/32/606_2.png) [@Pkeod](https://forum.defold.com/u/Pkeod)\
**Post date:** [November 6, 2017, 12:39am UTC](https://forum.defold.com/t/receive-project-path-in-macos-from-lua-solved/13375/4 "2017-11-06T00:39:49Z")

</div>

There are a couple of ways to do it and I’m not sure the best way… you can make a native extension to use built in osx functions to get it

```lua
std::string([NSBundle mainBundle].executablePath.UTF8String)

```

> **[executablePath | Apple Developer Documentation](https://developer.apple.com/documentation/foundation/bundle/executablepath)**
>
> The full pathname of the receiver’s executable file.

> **[executablePath | Apple Developer Documentation](https://developer.apple.com/documentation/foundation/bundle/executablepath)**
>
> The full pathname of the receiver’s executable file.

Would return full path to the engine exectuable I think.

You can also do it based on PID.

I don’t have a Mac handy at the moment to test.

Keep in mind it’s non-trivial to get access to the files Defold packs into the game’s resource files. If you add the files to the .app file it’s no problem.

It would probably be useful if someone made a “where am I” native extension for the various platforms.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [November 6, 2017, 5:24am UTC](https://forum.defold.com/t/receive-project-path-in-macos-from-lua-solved/13375/5 "2017-11-06T05:24:13Z")

</div>

> [@tarnumius](#):
>
> In Windows project read files from application dir by default, but in macOS no and required absolute path.

sys.save() and sys.load() works on the application root on OSX. So does io.open().

> [@Pkeod](#):
>
> It would probably be useful if someone made a “where am I” native extension for the various platforms.

You mean like `lfs.currentdir()`? 😉 ([https://www.defold.com/community/projects/76577/](https://www.defold.com/community/projects/76577/) and [https://keplerproject.github.io/luafilesystem/manual.html#reference](https://keplerproject.github.io/luafilesystem/manual.html#reference))

---

<div class="post-metadata">

**Author:** ![tarnumius](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@tarnumius](https://forum.defold.com/u/tarnumius)\
**Post date:** [November 6, 2017, 7:53am UTC](https://forum.defold.com/t/receive-project-path-in-macos-from-lua-solved/13375/6 "2017-11-06T07:53:59Z")

</div>

Thank you guys. I think LFS resolve my problem.

---

<div class="post-metadata">

**Author:** ![dapetcu21](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/dapetcu21/32/25120_2.png) [@dapetcu21](https://forum.defold.com/u/dapetcu21)\
**Post date:** [March 12, 2018, 8:26pm UTC](https://forum.defold.com/t/receive-project-path-in-macos-from-lua-solved/13375/7 "2018-03-12T20:26:40Z")

</div>

`defos.get_bundle_root()` also does this now (thanks to @AGulev).
