Jump to content

Embedding AppleScript IN cocoa with objective-c


7 posts in this topic

Recommended Posts

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

ahhh, thanks :D

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.  :D

 

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

 Share

×
×
  • Create New...