Question: When I archive from the command line using `xcodebuild archive`, how can I get the path to the newly created archive? I'd like to follow on with an `-exportArchive` command to create an adhoc distribution.

I know that I can define an `-archivePath`, however if I do that then Organizer doesnt know where about this archive, so that's no good.

Thoughts?

Answer: 
There's `$ARCHIVE_PATH` variable that's only available in archive post-actions scripts[![enter image description here](https://i.stack.imgur.com/vz0vF.png)](https://i.stack.imgur.com/vz0vF.png)

**Edit:**
`$ARCHIVE_PATH` returns a kind of generic path that doesn't account for the date, time, or duplicate suffixes.

Use `$ARCHIVE_PRODUCTS_PATH` instead. Or actually `REAL_ARCHIVE_PATH=$(dirname ${ARCHIVE_PRODUCTS_PATH})`.
Assuming that you have a standard archives path on your machine, I use this python code to get me the current archive path for builds.

```
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import datetime

class Xcodebuild:

    @staticmethod
    def current_archive_path():
        # The default archives path is as follows
        #
        #    /Users/<USER>/Library/Developer/Xcode/Archives/<YYYY>-<MM>-<DD>
        #
        home = os.path.expanduser("~")
        archives_path = os.path.join(home, "Library/Developer/Xcode/Archives")

        if not os.path.isdir(archives_path):
            exit("error: Xcode archives directory not found at {}".format(archives_path))

        dirname = str(datetime.date.today())
        archive_path = os.path.join(archives_path, dirname)

        if not os.path.exists(archive_path):
            os.makedirs(archive_path)

        return archive_path

```