Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Xcode

Hi all,

I just started using Xcode, so these questions will seem very easy and "newbie-ish" to many.


Obj-C:

I'm not sure which text field I need to fill in to give a certain NSButton or other object a name so I can access in the actual code (please don't give me the usual "check the documentation" because the reason I'm posting this is to get a straightforward answer that very often only humans can provide). Also, what method do I need to use to listen for "action events" as they are called in Java on an NSButton (i.e. how to I make a method run when the button is clicked on)? If anyone can suggest a good website where I can find tutorials to learn Objective-C that would be very helpful, so I don't need to post everything here.


C++:

Xcode gives you the option to make new files in your project, but how do I access them? I'm making a C++ command line tool to allow me to run commands that I always run without creating a login item (because they slow my Mac down). I made a new file as a "shell script" but I don't know how to run this script in the C++ code.

Posted on Sep 8, 2013 11:14 AM

Reply
Question marked as Best reply

Posted on Sep 8, 2013 1:47 PM

Have a look at Start Developing Mac Apps Today from Apple will answer your two Obj-C questions better then i can.

10 replies

Sep 9, 2013 8:52 AM in response to Frank Caggiano

I need C++ to read user input because I do not of any commands in bash to read user input.


I downloaded Xcode without knowing any Objective-C because I knew I wanted to develop for Mac, but now I know how to create command line tools with C++ in Xcode. I thought I might make a command line tool for this purpose because I don't know of any bash commands that read user input and react accordingly.


Just to clarify, I will state the purposes of my application. When I login, there are many apps I always open. However, adding them all to my login items slows down my Mac and prevents me from accomplishing other tasks while I wait for these apps to open. Also, there are some apps that I only open on some occasions, like Mail (which I only open if there is an internet connection available, e.g. not on an airplane). I want to create this app to read user input asking "Do you want to open this?" and then open only the apps which I specify.


Message was edited by Arc676 due to lack of clarity

Sep 10, 2013 6:49 AM in response to Arc676

If you know C++ then the way you would do the task you are trying to do on other platforms would be basically the same in OS X.


If you wanted to you could write your C++ code in an regular editor and compile the program on the command line in the Terminal, the system doesn't not force you to use Xcode for something like this.


I personally would use Xcode because I find the IDE to be useful. If you are going to eventually do any Objective-C programming you will need to use Xcode then so learning it now will be a plus.


If you have specific C++ questions you can try posting them here I'm sure you'll get responses. I myself have been fortunate in not having ever needed to use it 😉


regards

Sep 11, 2013 4:30 AM in response to Frank Caggiano

I don't think I was very clear in my last post. What I'm trying to do is create a tool that read user input from the command line (i.e. Terminal) and open only specified apps depending on user input. If you know a bash command like "read >> theVariable" or something like that, that would also help, but I don't know of the possibility of creating if conditions in a shell script. That is why I decided to create an app for it. So in C++ code it would read user input other the prompt "Do you want to open Mail?" and if the user input equals "y" the app will load the shell script (located in the same folder as the source code) and run it. Inside the shell script would be the bash command "open -a mail". I hope this clarifies for anyone else who reads this.

Sep 11, 2013 4:34 AM in response to Arc676

I don't think I was very clear in my last post. What I'm trying to do is create a tool that reads user input from the command line (i.e. Terminal) and open only specified apps depending on user input. If you know a bash command like "read >> theVariable" or something like that, that would also help, but I don't know of the possibility of creating if conditions in a shell script. That is why I decided to create an app for it. So in C++ code it would read user input with the prompt "Do you want to open Mail?" and if the user input equals "y" the app will load the shell script (located in the same folder as the source code) and run it. Inside the shell script would be the bash command "open -a mail". I hope this clarifies my question anyone else who reads this.


Message was reposted by Arc676 due to spelling errors

Sep 12, 2013 7:45 AM in response to Arc676

I need to add to my original question, just to avoid posting a new thread. When I run my app, the components of the NSWindow are not correctly placed (i.e. the radio buttons are not as far apart as they appear in the interface builder, and a set of labels and color wells are farther apart than in the interface builder, and the window is taller than shown in the interface builder). Does anyone know a solution/explanation for this?

Xcode

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.