371273
371273

Reputation: 5436

NSAppleScript Wont Work

Can someone please tell me why this won't work?

NSAppleScript* playPause = [[NSAppleScript alloc] initWithSource:
    @"\
    tell application \"System Events\"\n\
     tell application \"Final Cut Pro\" to activate\n\
     keystroke \" \"\
    end tell"];

I get the error "Expected ':' ',' ';' '}' or 'attribute' before '=' token". WTF?

Thanks for your help!

Upvotes: 2

Views: 1723

Answers (1)

Yuji
Yuji

Reputation: 34185

Putting a backslash before the newline inside a string literal does not work in C, Objective-C, or C++.

Just use

NSAppleScript* playPause = [[NSAppleScript alloc] initWithSource:
    @"tell application \"System Events\"\n"
    @"    tell application \"Final Cut Pro\" to activate\n"
    @"    keystroke \" \""
    @"end tell"];

using automatic concatenation of string literals.

Upvotes: 7

Related Questions