On this page
Every iOS and macOS app stores its configuration in a plist file, and the app’s BundleID lives in there alongside the version number. Read the plist and you’ve got both. Taking Store.app as an example, its plist sits at the path shown below — every other app follows the same pattern.

Open the plist and you’ll see the app’s configuration inside, like this:

A plist is essentially XML, so we want the value paired with the key CFBundleIdentifier. In the screenshot above that’s line 51, with line 52 holding the value — com.apple.AppStore.
Now that we know the principle, the tooling is easy. macOS ships with PlistBuddy: feed it the path to a plist and ask it for a key’s value.

For more on PlistBuddy, see What is PlistBuddy?