run an app from terminal

Discussion in 'Mac Programming' started by Binju, Mar 29, 2010.

  1. Binju macrumors member

    Joined:
    Jan 31, 2010
    #1
    I create a cocoa application using xcode and i build it.

    But i want to run the app from the terminal?

    How to run an app from terminal?
     
  2. sammich macrumors 601

    sammich

    Joined:
    Sep 26, 2006
    Location:
    Sarcasmville.
    #2
    Code:
    open -a <yourappname>
    Always seems to know where your app lives.
     
  3. Binju thread starter macrumors member

    Joined:
    Jan 31, 2010
  4. sammich macrumors 601

    sammich

    Joined:
    Sep 26, 2006
    Location:
    Sarcasmville.
    #4
    What command are you running?

    And what is the name of your app (is it a compiled as a .app?) and where is it located?
     
  5. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #5
    You're not providing enough detail.

    Post the exact command-line you tried. Copy and paste it into a post.
     
  6. Binju thread starter macrumors member

    Joined:
    Jan 31, 2010
  7. robj macrumors regular

    Joined:
    Dec 23, 2009
    Location:
    Madrid, Spain
    #7
    Even if it's not the best option, you can 'cd' into the filename.app folder and find the executable inside "filename.app/Resources/MacOS/" ( or around there ) folder and run it.

    In the end, Finder shows the *.app file as a program but it's really a folder with the resources and the executables packed into.
     
  8. Binju thread starter macrumors member

    Joined:
    Jan 31, 2010
    #8
    Is it possible to pass the parameter with the open command in the terminal

    For example,I need to play a song in a player,The songs list should come from a playlist.playlist so the playlist.playlist is a parameter of my app

    So i need to pass
    Code:
    open filename.app playlist.playlist
     
  9. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #9
    Code:
    man open
    answers all!

    Edit: I'm feeling nice. Use:
    Code:
    --args
     
  10. Binju thread starter macrumors member

    Joined:
    Jan 31, 2010
    #10
    [ Use:
    Code:
    --args
    [/QUOTE]


    ok.

    So the code is
    Code:
    open filename.app --player.playlist
    How can I get the player.playlist in to my application
     
  11. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #11
    Did you read the man page, as Cromulent suggested?
     
  12. Binju thread starter macrumors member

    Joined:
    Jan 31, 2010
    #12
    I wrote an application that plays the playlist from the resources of the application

    What i want to do is , I need to play the playlist from some particular path

    So if i give

    Code:
    open filename.app --args user/me/Player.playlist  
    in the terminal

    My app should play the playlist from the user/me/Player.playlist.

    If I give the above command in the terminal,myapp is opened and play the playlist in the resource.

    But I dont know how to say to my app to take the playlist path specified in the terminal

    Any idea?
     
  13. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #13
    Try a Google search for "Cocoa application handle command line arguments". The very first result will tell you one option for getting the command line arguments in Cocoa.
     
  14. Binju thread starter macrumors member

    Joined:
    Jan 31, 2010
    #14
    When i run my app from terminal , In the console it does not display anything.

    Why?
     

Share This Page