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

Similar Threads
thread Thread Starter Forum Replies Last Post
Cocoa Application: Setting Custom Background Image ajbudis Mac Programming 1 Jul 22, 2013 11:42 AM
Saving a cocoa application to like an executable. RookieAppler Mac Programming 16 Feb 11, 2013 11:02 AM
Need Assitance in creating a simple Cocoa OS X application lilabila Mac Programming 2 Aug 18, 2012 12:52 PM
How to show/hide objects in Cocoa Applescript application sjmonty99 Mac Programming 3 Aug 6, 2012 11:02 AM
How to pass commandline argument in cocoa application? Ram Thakkar Mac Programming 1 Jul 7, 2012 06:57 AM

Forum Jump

All times are GMT -5. The time now is 09:03 AM.

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

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