views:

87

answers:

2

I'm trying to do something like this:

NSAppleScript *sendCharlieImput = [[NSAppleScript alloc] initWithSource:@"tell application \"terminal\" to do script " charlieImputSelf " in front window"];
[sendCharlieImput executeAndReturnError:nil];

The variable charlieImputSelf is going to be put into the terminal window as a command. BUT I need to put charlieImputSelf in between 2 qoutes (like above). This is obviously not the correct way. Can someone help?

Thanks! Elijah

+2  A: 

Use NSString's +stringWithFormat: method:

NSAppleScript *sendCharlieImput = [[NSAppleScript alloc] initWithSource:[NSString stringWithFormat:@"tell application \"Terminal\" to do script %@ in front window", charlieImputSelf]];
macatomy
+9  A: 

To be successful, you'll need to embrace the documentation. Start here. Then go read this.

Going down the path of having to ask a question on SO about every line of code is not going to lead to success.

To answer this question, you want stringWithFormat::

[NSString stringWithFormat: @"some random string \"with quotes\" and %@ word in the middle.", @"this"]; 
bbum