views:

145

answers:

1

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!

+4  A: 

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.

Yuji
thanks! fixed it!
Wind Up Toy
The syntax is no longer a problem, but when i use[playPause executeAndReturnError:nil];nothing happens. Is there a better way to execute the appleScript?
Wind Up Toy
Does the script itself work? I don't have FCP so I can't test it myself. And I think I forgot `\n` after keystroke, sorry about that. I would keep the script in a separate file and use `-[NSAppleScript initWithContentsOfURL:error:]` instead.
Yuji