Alternates to quotation marks in Objective C

90 views Asked by At

I have this line of code in a method:

system("osascript -e 'tell app "System Events" to restart'");

As you can see, I've got two quotation marks, and since these terminal commands have to be so specific, I need to know another way to run a system command from ObjC. I've already tried using '' and the / method but that didn't work out.

1

There are 1 answers

2
Ken Thomases On BEST ANSWER

You need to "escape" the quote characters to tell the compiler that the should be part of the string rather than delimiters of the string. You say you "tried using … the / method", but you got the wrong character. You escape characters using the backslash, not the forward slash:

-(IBAction)reboot:(id)sender{
    system("osascript -e 'tell app \"System Events\" to restart'");
}