39

How do I get the bundle Id of the app I am in ?

nschum
  • 15,322
  • 5
  • 58
  • 56
swathy valluri
  • 5,039
  • 2
  • 16
  • 13

3 Answers3

118

You'd use:

[[NSBundle mainBundle] bundleIdentifier]

+ mainBundle "[r]eturns the NSBundle object that corresponds to the directory where the current application executable is located." and hence will return an NSBundle object for the application bundle.

[- bundleIdentifier] Returns "[t]he receiver’s bundle identifier, which is defined by the CFBundleIdentifier key in the bundle’s information property list."

Tommy
  • 99,986
  • 12
  • 185
  • 204
8

Here is how I got the Bundle Id for my APP in the UIA Scripts:

//code to get bundle id
var target = UIATarget.localTarget();
var app_name = target.frontMostApp().bundleID();
UIALogger.logDebug(app_name);
swathy valluri
  • 5,039
  • 2
  • 16
  • 13
4

You can findle the bundle id from the plist. Right Click in the app file and click on "show package contents". You will find a plist file there. Open it with any text editor and you will get the bundle id.

Sanjay
  • 97
  • 4
  • 3
    Not false, but obviously the question was about getting the bundle id **from code**, not from the finder. You must read carefully the question, and other answers before answering. – psycho Sep 25 '12 at 07:50
  • 2
    The question was regarding UIA Automation and is not related to source code. We always use app or ipa file for that and not the source code, So you better re read that question – Sanjay Jan 29 '13 at 05:20
  • 4
    Funny, I would have sworn that "automation" would mean using a script, so, code. – psycho Jan 29 '13 at 13:12