Console Application capture OS Signal on file double click

Discussion in 'Mac Programming' started by Draque, Mar 15, 2015.

  1. Draque, Mar 15, 2015
    Last edited: Mar 15, 2015

    Draque macrumors newbie

    Joined:
    Jan 6, 2015
    #1
    I've spent days attacking this and at this point am wondering if what I am trying to do is even possible.

    I have a bundled app. In the Contents/MacOS path of the bundle is a console application that when run, goes off and does its own thing. If the app is opened because the user double clicked a file associated with it, or dropped the file on the icon of the app, it must be able to capture the full path of that file.

    All of the solutions that I've found have been for a UI based app. Is there any possible way to capture this in a console program like the one I have below? This problem is absolutely killing me. I've wasted so much time on it that at this point, I'm considering scrapping the Mac version of my application entirely.

    It seems like this must be an incredibly basic thing to do, but so far it's proven infuriating at every turn. Infinite gratitude to anyone who can help me here.

    I have modified the Info.plist file to include:
    Code:
    <key>CFBundleDocumentTypes</key>
            <array>
                <dict>
                    <key>CFBundleTypeExtensions</key>
                    <array>
                        <string>pgt</string>
                    </array>
                    <key>CFBundleTypeIconFile</key>
                    <string>macSet.icns</string>
                    <key>CFBundleTypeMIMETypes</key>
                    <array>
                        <string>text/xml</string>
                    </array>
                    <key>CFBundleTypeName</key>
                    <string>XML File</string>
                    <key>CFBundleTypeRole</key>
                    <string>Viewer</string>
                    <key>LSIsAppleDefaultForType</key>
                    <true/>
                </dict>
            </array>
    
    I have included the following code in the class:
    Code:
    @implementation JavaAppLauncherCustom
    
    - (BOOL)application:(NSApplication *)WrapperApp openFile:(NSString *)filename
    {
        <DO STUFF>
    
        return [self processFile:filename];
    }
    @end
    
    My <DO STUFF> is never hit when I drag/drop files of my type over the application. Any guidance?

    Edit: I'm primarily a Java developer, and am really just trying to get this wrapper to present my program. Sorry for the low level of familiarity I have with objective C. It's something I'm trying to pick up here on the fly.
     
  2. Red Menace macrumors 6502

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #2
    What OS/Xcode/project template are you using? Xcode has a command line project template, but it doesn't create an application bundle.
     
  3. Draque thread starter macrumors newbie

    Joined:
    Jan 6, 2015
    #3
    Thank you for responding! I'm using a bundle that was created from AppBundler. I have the source code for JavaAppLauncher, which is when I'm working on modifying to drop back int the bundle that was created. I just created a console application and dropped the source code in. When I compile that, I can replace the console program that's already in the bundle.

    The bundle itself works fine, I just need to know how, within the console app, to grab the opened file's path.
     

Share This Page