bronxbomber92 Posted August 20, 2006 Share Posted August 20, 2006 So how can it be done? Link to comment Share on other sites More sharing options...
grabberslasher Posted August 20, 2006 Share Posted August 20, 2006 Very easily. Something like this: NSString *myScript = @"tell application \"iTunes\" \n activate \n end tell"; NSAppleScript *script = [[NSAppleScript alloc] initWithSource:myScript]; [script executeAndReturnError:nil]; Link to comment Share on other sites More sharing options...
bronxbomber92 Posted August 20, 2006 Author Share Posted August 20, 2006 so does pointer "myscript" contain the applescript? Could you explain that code, I'm kinda confused... Thanks Link to comment Share on other sites More sharing options...
bronxbomber92 Posted August 22, 2006 Author Share Posted August 22, 2006 Can anyone explain further? Thanks Link to comment Share on other sites More sharing options...
SaberSHO Posted August 22, 2006 Share Posted August 22, 2006 NSString *myScript = @"tell application \"iTunes\" \n activate \n end tell"; NSAppleScript *script = [[NSAppleScript alloc] initWithSource:myScript]; [script executeAndReturnError:nil]; the applescript is contained in the NSString object pointed too by the myscript pointer. THe actuall string would look like this (remember /n is a newline character and /" represents the character ") tell application "iTunes" activate end tell which is a perfectly normal looking applescript. thenm an NSAppleScript object pointed too by script gets allocated and then initizialid with the previously made string myScript. When you tell the script to execute, it look at its source, which in this case was set with the initWithSource:myScript command and runs that applescript. Hope this clarified Link to comment Share on other sites More sharing options...
bronxbomber92 Posted August 22, 2006 Author Share Posted August 22, 2006 ahhh, thanks That helped a lot! Cheers Link to comment Share on other sites More sharing options...
grabberslasher Posted August 22, 2006 Share Posted August 22, 2006 ahhh, thanks That helped a lot! Cheers Sorry, I didn't think of explaining the code. I'm used to being given code and then using the Xcode docs to find out how it works. Yes, myScript contains the script as a string, and each new line is using the \n newline character. I haven't actually tested the above code, but it's something like that. Link to comment Share on other sites More sharing options...
Recommended Posts