Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

LinusR

macrumors 6502
Original poster
Jan 3, 2011
332
515
Good evening,

I would like to use an AppleScript. This AppleScript contains names with quotation marks (""). But to use them in AppleScript I have to use \". Now I tried to replace them by
Code:
- (NSString *)stringByReplacingOccurrencesOfString:(NSString *)target withString:(NSString *)replacement

But how shall I declare the quotation mark? My first try looked like this:

Code:
NSString *name = [[textField stringValue] stringByReplacingOccurrencesOfString:@"\"" withString:@"\""];

But because of the (\) Objective-C thinks I want to replace " with ". Can anyone help? My AppleScript looks like this:

Code:
NSString *script = [NSString stringWithFormat:@"tell application \"iTunes\" \n play (every track of playlist 1 whose name is \"%@\") \n end tell", name];

iTunes doesn't play the track when the track title contains quotation marks. So they have to be replaced by (\"). Does anyone know a solution?

Thanks in advance,

Linus

EDIT: Wrong orthography
 

rossipoo

macrumors regular
Jun 7, 2009
109
0
\\ will insert a backslash into a string.

For example:
[string stringByReplacingOccurrencesOfString:mad:"\"" withString:mad:"\\\""]
 

LinusR

macrumors 6502
Original poster
Jan 3, 2011
332
515
\\ will insert a backslash into a string.

For example:
[string stringByReplacingOccurrencesOfString:mad:"\"" withString:mad:"\\\""]

Thanks, this worked awesome!

Thanks for your help,

Have a nice day,

Linus
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.