Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 16, 2009, 05:23 AM   #1
ruhi
macrumors member
 
Join Date: Jun 2009
Apple Script + Cocoa Application

Hello, I am trying to add a small apple script to my cocoa application.

what do i need to do to make it execute and give desired result

Following are the two ways i used:
1.

NSString *scriptPath = [[NSBundle mainBundle] pathForResource: @"your_script" ofType: @"scpt"];
NSAppleScript *theScript = [[NSAppleScript alloc] initWithContentsOfURL: [NSURL fileURLWithPath: scriptPath] error: nil];

But here i found that scriptPath come out to be nil.

what is the problem here i am getting the path for other resources but not for my script.

2.

The script is

tell application "System Events"
set frontApp to name of first application process whose frontmost is true
end tell
tell application frontApp
if the (count of windows) is not 0 then
set window_name to name of front window
end if
end tell

so i wrote:

NSAppleEventDescriptor *str;
NSAppleScript *playScript;
playScript = [[NSAppleScript alloc] initWithSource:@"tell application \"System Events\" \n set frontApp to name of first application process \n whose frontmost is true \n end tell \n tell application frontApp \n if the (count of windows) is not 0 then \n set window_name to name of front window \n end if\n end tell"];
str=[playScript executeAndReturnError:&dict];
NSLog(@"err - %@",dict);
NSLog(@"Output --- %@",str );


Here is the error its giving and Output always comes null that should give title of active window:

err - {
NSAppleScriptErrorBriefMessage = "Expected \U201cend\U201d or \U201cend tell\U201d but found \U201cwhose\U201d.";
NSAppleScriptErrorMessage = "Expected \U201cend\U201d or \U201cend tell\U201d but found \U201cwhose\U201d.";
NSAppleScriptErrorNumber = -2741;
NSAppleScriptErrorRange = NSRange: {87, 5};
}
2009-07-16 15:50:43.509 Web[2964:10b] Output --- (null)

What is the problem here? where i am wrong. Please correct me.

Do i need to add some framework or do some changes in plist for the apple script to run in my cocoa application
ruhi is offline   0 Reply With Quote
Old Jul 16, 2009, 05:43 AM   #2
ruhi
Thread Starter
macrumors member
 
Join Date: Jun 2009
Solved

Go the problem solved thanx.
ruhi is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Automator/Apple Script Help - Application Requires Password nicksoper Mac Programming 8 Oct 18, 2010 02:49 PM
Making Script and executing with cocoa application ruhi Mac Programming 1 Aug 29, 2009 05:15 AM
Suitable Path for Application Data in Cocoa Application ruhi Mac Programming 6 Jul 25, 2009 03:55 AM
Installers for Cocoa Applications vnraju Mac Programming 7 Oct 23, 2007 11:08 AM
Help with embedding a command line tool within a Cocoa application? mrichmon Mac Programming 2 Feb 23, 2006 01:25 AM


All times are GMT -5. The time now is 05:50 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC