receiving a file on app startup

  • Hey there,

    I would like a Cocoa application to accept files on startup. As an
    example - you can drop images onto the photoshop icon which will
    start the application and open the images. As this is not really drag-
    and-drop in the sense of what you find via Google, it would be great
    to get some pointers here.

    cheers
    --
    Torsten
  • > I would like a Cocoa application to accept files on startup. As an
    > example - you can drop images onto the photoshop icon which will
    > start the application and open the images. As this is not really
    > drag-and-drop in the sense of what you find via Google, it would be
    > great to get some pointers here.
    >

    It's actually quite simple, if your app can open the file, the app
    will start up and open it when you drop it on your icon. Did you
    actually try?

    Cheers, Patrick
  • On 03.02.2008, at 22:01, PGM wrote:

    >> I would like a Cocoa application to accept files on startup. As an
    >> example - you can drop images onto the photoshop icon which will
    >> start the application and open the images. As this is not really
    >> drag-and-drop in the sense of what you find via Google, it would
    >> be great to get some pointers here.
    >>
    >
    > It's actually quite simple, if your app can open the file, the app
    > will start up and open it when you drop it on your icon. Did you
    > actually try?

    Of course :)

    I've used the default XCode templates (document and non-document
    based). Now when I try to drag something onto that application - I
    just can't. Do I maybe just need to enable that application for the
    particular file type? An what happens if the app is not document based?

    As a little test project I would like to receive the file and just
    save it to /tmp.

    cheers
    --
    Torsten
  • > On 03.02.2008, at 22:01, PGM wrote:
    >
    >>> I would like a Cocoa application to accept files on startup. As an
    >>> example - you can drop images onto the photoshop icon which will
    >>> start the application and open the images. As this is not really
    >>> drag-and-drop in the sense of what you find via Google, it would
    >>> be great to get some pointers here.
    >>>
    >>
    >> It's actually quite simple, if your app can open the file, the app
    >> will start up and open it when you drop it on your icon. Did you
    >> actually try?
    >
    > Of course :)
    >
    > I've used the default XCode templates (document and non-document
    > based). Now when I try to drag something onto that application - I
    > just can't. Do I maybe just need to enable that application for the
    > particular file type? An what happens if the app is not document
    > based?
    >
    > As a little test project I would like to receive the file and just
    > save it to /tmp.
    >

    Well, the default templates miss the necessary code to actually open
    files in any way. Though they are actually already quite advanced,
    they are really templates that you need to expand upon and are not
    able to just open any file you throw at them. So if your app needs to
    be able to read a document, you need to add code for that.
    Furthermore, you indeed need to enable the app for the file type (or
    enable all files by entering a *). Look at the "build a text-editor in
    ten minutes" tutorials that are available at several places on the web
    for examples how to do this stuff.

    Good luck, Patrick
  • On Feb 3, 2008, at 13:34, Torsten Curdt wrote:

    > Do I maybe just need to enable that application for the particular
    > file type?

    Yes. It's in the build properties for the target. There's a place
    where you can list the document types your app can open, specified by
    any combination of extension, 4-char OS type, MIME type or UTI type.
    (Apple seems to be pushing UTI atm.) This list ends up in your app's
    info.plist, and that's where LaunchServices discovers it, and that's
    how the Finder knows to enable the drag and drop.
  • >> Do I maybe just need to enable that application for the
    >> particular file type?
    >
    > Yes. It's in the build properties for the target. There's a place
    > where you can list the document types your app can open, specified
    > by any combination of extension, 4-char OS type, MIME type or UTI
    > type. (Apple seems to be pushing UTI atm.) This list ends up in
    > your app's info.plist, and that's where LaunchServices discovers
    > it, and that's how the Finder knows to enable the drag and drop.

    Ha! In the target settings! Thanks!

    cheers
    --
    Torsten
  • You have to define CFBundleTypeExtensions in the InfoPlist file.  This
    will get you started...

    http://developer.apple.com/documentation/Cocoa/Conceptual/Documents/Concept
    s/DocTypePList.html


    On Feb 3, 2008, at 2:51 PM, Torsten Curdt wrote:

    > Hey there,
    >
    > I would like a Cocoa application to accept files on startup. As an
    > example - you can drop images onto the photoshop icon which will
    > start the application and open the images. As this is not really
    > drag-and-drop in the sense of what you find via Google, it would be
    > great to get some pointers here.
    >
    > cheers
    > --
    > Torsten
  • him
    did u succed with that task?
    which selector/method do you need to implement when the application
    open the file?

    > You have to define CFBundleTypeExtensions in the InfoPlist file.
    > This will get you started...
    >
    > http://developer.apple.com/documentation/Cocoa/Conceptual/Documents/Concept
    s/DocTypePList.html

  • On 05.02.2008, at 16:14, Davide Scheriani wrote:

    > him
    > did u succed with that task?
    > which selector/method do you need to implement when the application
    > open the file?

    Yes, you specify the class along with the file types on the target
    configuration. That class itself needs to be derived from NSDocument
    and have the methods

    - (NSData *)dataRepresentationOfType:(NSString *)aType
    - (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType

    Then you are set :)

    cheers
    --
    Torsten
  • Hi,

    Note that as of Tiger, -dataRepresentationofType: and -
    loadDataRepresentation:ofType: are deprecated.  For Tiger and above,
    use:

    - (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
    - (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:
    (NSError**)outError

    instead.

    Cheers,
    Andrew

    On Feb 5, 2008, at 7:26 AM, Torsten Curdt wrote:

    >
    > On 05.02.2008, at 16:14, Davide Scheriani wrote:
    >
    >> him
    >> did u succed with that task?
    >> which selector/method do you need to implement when the application
    >> open the file?
    >
    > Yes, you specify the class along with the file types on the target
    > configuration. That class itself needs to be derived from NSDocument
    > and have the methods
    >
    > - (NSData *)dataRepresentationOfType:(NSString *)aType
    > - (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType
    >
    > Then you are set :)
    >
    > cheers
    > --
    > Torsten
  • hi again,
    Ive implemented the method readFromData and loadDataRepresentation but
    after reading,processing (unarchiving)
    the data and reinsert into my objects/arrays, I cannot control
    anything on my window (enable the buttons and refresh the nstableview).
    what shoud I do?

    > Hi,
    >
    > Note that as of Tiger, -dataRepresentationofType: and -
    > loadDataRepresentation:ofType: are deprecated.  For Tiger and above,
    > use:
    >
    > - (NSData *)dataOfType:(NSString *)typeName error:(NSError
    > **)outError
    > - (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName
    > error:(NSError**)outError
    >
    > instead.
  • On Feb 6, 2008 4:53 AM, Davide Scheriani
    <dscheriani...> wrote:
    > hi again,
    > Ive implemented the method readFromData and loadDataRepresentation but
    > after reading,processing (unarchiving)
    > the data and reinsert into my objects/arrays, I cannot control
    > anything on my window (enable the buttons and refresh the nstableview).
    > what shoud I do?

    You should learn how to debug your application, and then if you're
    stumped come back with a more descriptive version of your problem.  It
    sounds like you're doing something wrong... perhaps posting your code
    would be helpful.

    --Kyle Sluder
  • You should really re-read the document architecture documentation.
    And the memory management guide.  First, by returning @"MainMenu" from
    -windowNibName, you are loading your main nib every time you create a
    new document.  This is not what you want to do; the document docs
    explain this concept.  Secondly, the array you're getting back from
    the NSArchiver is going to be autoreleased from under your feet (I'm
    assuming you haven't attempted to work with garbage collection yet).

    Please thoroughly read the documentation, and dig deep into Apple's
    sample code.  You'll do yourself a lot of good.

    --Kyle Sluder
previous month february 2008 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29    
Go to today
MindNode
MindNode offered a free license !