Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Terminating an Xcode app after run?

I'm making an Xcode application, in Cocoa-Applescript, and I'de like to make it quit after it runs through the script. Is that possible? I've tried:


[[UIApplication sharedApplication] terminate];


and



exit(0);


but when I go to build it I get the error "Command /usr/bin/osacompile failed with exit code 1". How can I go about this?

Posted on Apr 17, 2013 1:13 PM

Reply
13 replies

Apr 17, 2013 5:07 PM in response to Apple_For_The_Win

Applications in Xcode (AppleScript and otherwise) are typically event driven, so they do not terminate unless one of the standard ways such as the quit menu item is used, or there is a statement that quits the application. When using a program statement, you do need to use a valid AppleScriptObjC or regular AppleScript statement, or you will get a syntax error (the osacompile bit).

Apr 17, 2013 6:30 PM in response to Frank Caggiano

--

-- AppDelegate.applescript

-- Mc_Launcher

--

-- Created by Alex Lieflander on 13-04-16.

-- Copyright (c) 2013 Liefy. All rights reserved.

--


script AppDelegate


property parent : class "NSObject"


on applicationDidFinishLaunching_(aNotification)



--Edited out the string of commands, it was 600 lines...


end applicationDidFinishLaunching_


end script

Apr 17, 2013 6:33 PM in response to Apple_For_The_Win

Simple program. Starts puts up an Applescript dialog quirs when the dialog is dismissed.


--

-- AppDelegate.applescript

-- ASCTestQ

--

-- Created by Frank Caggiano on 4/17/13.

-- Copyright (c) 2013 Frank Caggiano. All rights reserved.

--


script AppDelegate


propertyparent : class"NSObject"


on applicationWillFinishLaunching_(aNotification)


-- Insert code here to initialize your application before any files are opened

display dialog "Running"

tellmetoquit

end applicationWillFinishLaunching_


on applicationShouldTerminate_(sender)


-- Insert code here to do any housekeeping before your application quits

return current application's NSTerminateNow

end applicationShouldTerminate_


endscript

Apr 17, 2013 6:42 PM in response to Apple_For_The_Win

If your application has no user interface, maybe Xcode is overkill. In that case, the Cocoa-AppleScript Applet template from the AppleScript Editor might be the better tool, since it recreates the usual handlers (such as run) but can also use various Cocoa methods. You will still need to manually quit the application, though.


Edit: a better description might be that it provides wrappers for the standard handlers, in that it will use them like a regular AppleScript if a handler is there.

Terminating an Xcode app after run?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.