Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7956959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:09:08+00:00 2026-06-04T04:09:08+00:00

I was wondering if it is possible to pass arguments between Mac applications and

  • 0

I was wondering if it is possible to pass arguments between Mac applications and if it possible, how.

I know that in Java is possible using the following syntax from the command line:

java JavaApp arg1 arg2 arg3 arg4

And that is possible to access those through the main’s args[] array.

public static void main(String[] args) {
        System.out.println("d");
        for (int i = 0; i < args.length; i++)
            System.out.println(args[i]);
}

Edit: I want to pass the arguments from a command line Mac application to a Cocoa Mac application

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:09:09+00:00Added an answer on June 4, 2026 at 4:09 am

    All your answers worked properly for me, but I found another solution that suits better my needs.
    I needed to launch a Cocoa app from a Command Line Tool, which I achieved with the following line:

    system("nohup /PATH/Arguments.app/Contents/MacOS/Arguments argument1 argument2 &");
    

    nohup is unix service that allows you to attach processes to itself so if you close the terminal window, the process remains alive.

    Next problem that came along was capturing the arguments from within the Cocoa app. “How would I get the arguments from AppDelegate.m if main.m is the one that receives them and just returns an int.”

    Among Apple’s frameworks and libraries I found one that exactly solved the problem. This library is called crt_externs.h and contains two useful variables, one to learn the number of arguments, and another one to obtain the arguments themselves.

    extern char ***_NSGetArgv(void);
    extern int *_NSGetArgc(void);
    

    So, inside at the AppDelegate’s from the Cocoa app we would write the following code to parse the arguments into NSString’s:

    char **argv = *_NSGetArgv();
    NSString *argument1 = [NSString stringWithCString:argv[1] encoding:NSUTF8StringEncoding];
    NSString *argument2 = [NSString stringWithCString:argv[2] encoding:NSUTF8StringEncoding];
    

    As we can see we skip directly to the position 1 of the arguments array since position 0 contains the path itself:

    argv[0] = '/PATH/Arguments.app/Contents/MacOS/Arguments'
    argv[1] = 'argument1'
    argv[2] = 'argument2'
    

    Thank you all for your time and help. I learned a lot from you guys. I also hope this answer helps someone else 🙂

    Cheers and happy coding!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering, in java, is it possible to in anyway, simulate pass by
I was wondering if in C/C++ language it is possible to pass arguments to
I'm wondering if is possible pass types by argument in Java. Let me explain
I'm wondering if it is possible to pass form data from index.jsp file to
I was wondering if it is possible to pass back a variable from fancybox
I'm wondering if the following is possible: I've an app (service) that stays in
Possible Duplicate: Shell Script: How to pass command line arguments to an UNIX alias?
I was wondering ( if possible ) if there was a program/tool/utility that when
I was wondering - is it possible to change files that are stored on
i am wondering is that possible (best practice) to run two long running query

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.