7

I'm trying to create an Xcode plugin that should read all files contained in the project opened in Xcode and do further work with files names(Extract images names). The question is how to get the directory/path of the main bundle of the project opened in Xcode.

Thank you.

Ali Amin
  • 667
  • 5
  • 17

2 Answers2

11

Hi this way you can find the current project path from plugin

NSArray *workspaceWindowControllers = [NSClassFromString(@"IDEWorkspaceWindowController") valueForKey:@"workspaceWindowControllers"];

id workSpace;

for (id controller in workspaceWindowControllers) {
    if ([[controller valueForKey:@"window"] isEqual:[NSApp keyWindow]]) {
        workSpace = [controller valueForKey:@"_workspace"];
    }
}

NSString *workspacePath = [[workSpace valueForKey:@"representingFilePath"] valueForKey:@"_pathString"];
Eric
  • 5,671
  • 5
  • 31
  • 42
SachinVsSachin
  • 6,401
  • 3
  • 33
  • 39
-1

See the Apple Sandboxing Guide : https://developer.apple.com/library/mac/documentation/Security/Conceptual/AppSandboxDesignGuide/AppSandboxDesignGuide.pdf

If you want obtain the your bundle Directory:

NSString* bundle = [[NSBundle mainBundle] bundlePath];
santibernaldo
  • 825
  • 1
  • 11
  • 26
  • 1
    Sorry, this is not what I mean. When you are working on a plugin.The code you wrote will return Xcode's bundle path. that's because you are working on Xcode itself(check this[link] (http://www.blackdogfoundry.com/blog/creating-an-xcode4-plugin/)). So what I'm trying to know is how to get the path of the project that Xcode is opening. – Ali Amin Jan 11 '14 at 21:32