--- On Wed, 11/10/10, McLaughlin, Michael P. <mp...@mitre.org> wrote:
> Jonathan wrote: > >>> On 10 Nov 2010, at 18:34, McLaughlin, Michael P. wrote: >>> >>> Is there any standard way for a Cocoa app to test whether it was >>> launched from a script, esp. AppleScript? I would like to set a >>> flag to disable dialogs so that users could run the app in >>> (faceless) batch mode. >>> >>> Thanks. >>> >>> -- >>> Mike McLaughlin >>> >> >> Maybe it's just me but I am not sure if this question makes a whole >> lot of sense. >> >> AppleScript runs in process so a multitude of applications could >> launch your app by generating and dispatching the appropriate >> AppleEvent. >> Or do you want to ascertain if the app was launched by AppleScript >> Editor.app? >> >> Is the app to be scripted by users? >> >> In that case it might be better to make your app scriptable and send >> it an explicit event to request batch mode. > > The idea is that the app will be scriptable but I was trying to find > a way to avoid forcing the user to send a special command to set a > fromBatch flag (seems kludgy). > > I would like the user to be able to queue up a lot of separate input > files (jobs) for the app to 1) process and 2) save results, disabling > the various OK buttons, etc. that would normally have to be clicked. > That way, the user could launch a script and come back later to a > folder full of results without ever seeing the app. > > Most of the time, the normal app behavior would be interactive (a GUI). > > -- > > Mike McLaughlin Mike, What I did was to check the value of argc that your main function sees in main.m If there are more than 2 arguments (and that was something I never fully resolved - my app is 1 argument on the command line, but I never figured out what the 2nd one is). Regardless, if I call my application via: path to application.app folder/Contents/MacOS/applicationBinary with more than 2 arguments on the command line, I call a function to process command line arguments, which then directly initializes the necessary objects and puts my application in "batch mode". If argc <= 2, then in my code I call: return NSApplicationMain (argc, (const char **) argv); which happily launches a graphical front end and lets the user interact with my app from the OS X or GNUStep GUI (it can be compiled and run on either OS X or any linux distro that ships the GNUStep libraries). My solution is very ugly, but entirely functional for my needs. After I acquire data, I can pull up a sample via the GUI, see how the processing works, and can tweak parameters there and get direct feedback. I can then put those parameters into a shell script and drive the program in batch mode. I had my doubts when I first did this, but as ugly as it is under the hood, it's entirely stable and functional. Hope this helps! cheers vinai _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com