Run a binary from .app's package contents - objective-c

Can I have the binary files like .sh as part of the .app in "Package Contents".
I basically have .app which has 2 buttons start/stop which basically kicks off a process to start the server. To keep everything clean, I would like to store the start/stop shell scripts within the .app.
Can I execute those shell scripts from .app?

On the Mac, yes: use the NSTask class’s +launchedTaskWithLaunchPath:arguments: method (for example), after retrieving the path to the binaries with one of the methods on NSBundle’s—-resourcePath, -bundlePath, -pathForResource:ofType:, or whatever.
On iOS... no. NSTask isn’t available.

Yes. You'll want to look at NSTask to run your scripts or other binaries, and find the files using NSBundle's API.

Related

Is there a way for me to write a script in Robot Framework that utilize's the command line functions?

I'm currently working in Linux, and I know you can use Run Process to run certain applications, but I was wondering if there's a possible way to have my script running, open command line, input, for example: "clean" which in my case processes a few functions in my bash.rc. That would be extremely helpful in my automation right now.
Well essentially, what I did was I created a separate .sh executable file. Opened my .bashrc and copied my functions / aliases into my .sh file using the gedit editor. Then from my Robot Script, I used the Run Process command (I don't have my exact code at the moment) and called my executable file.

Can node webkit build in a single windows .exe file

I have a project that need to run in a pen drive, the content is updated daily, and i need a automated way to generate a single file (.exe) to be downloaded by users.
I use this tool https://github.com/mllrsohn/node-webkit-builder, but when build for windows, the build generate multiple files ( dlls, dat ,exe ).
This break my automation because the content need to be downloaded (single file).
Any help?
As far as I know, it can't. You could try making a 7zip SFX archive and running your own program instead of an installer.
This needs to create temporal files when run (which are deleted when the program quits) and I don't think you can remove the initial prompt. If you're okay with that, it might be what you need.
Edit: You can get the necessary SFX modules here.

How can I bundle a command line utility in os x application on Mac App Store (using sandbox entitlement)

I have a c++ command line application that I have already compiled into an executable and have added it into my Xcode project. I have also added the "Copy Files" section to the Build Phases tab of the project properties and added my executable with the "Executables" destination. When I build my application I see it in the test.app/Contents/MacOS folder when I View package contents on the test.app that is built.
I also have App Sandbox enabled on the Capabilities tab of the project (so that I can distribute my application through the mac app store.
How can I expose this command line executable that is bundled with my application to the user so that they can run it from the command line (terminal)? I have not been able to find anything on search engines or on StackOverflow about how to get this file (or a symlink to this file) into the users PATH. I tried using an NSTask to create a symlink, but that only works if I disable the App Sandbox (which makes sense). Has anyone done this before? How did you get it to work? Or can these executables only be executed by code within your application?
I don't see a good way to do this. First, a clarification: the PATH is a list of directories that contain executables, not a list of executables; there's no way to add a single executable to the PATH. Instead, what you'd need to do is either put your executable into one of the directories in the user's PATH, or add the directory your executable is in into the PATH.
On OS X, the default PATH is /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin. The first 4 directories shouldn't be modified from the system default, so only /usr/local/bin is a possibility. But creating it (it doesn't exist by default) would require admin (actually root) rights, which isn't allowed by App Store policies. So that's out.
That leaves modifying the user's PATH. The "right" way to do that system-wide is by placing a file in /etc/paths.d, which requires admin (/root) rights, so that's out too. Technically modifying the /etc/paths file would work, but that has the same permissions problem plus it's the wrong way to do customization.
The next possibility is to modify (/create) the user's shell initialization script(s). This'll work, but doing it at all right is going to be messy, because there are several shells the user might use, each with several different possible initialization scripts that the user might or might not have created...
Let's take a very simple case: a user who only ever uses bash, and who doesn't already have any initialization scripts. When a "login" instance of bash starts, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile (in that order), and runs the first one it finds. But your app doesn't know which shell he uses, so you'd better create ~/.profile so zsh and ksh will use it as well. So, your app creates ~/.profile, and puts this in it:
PATH="$PATH:/Applications/MyApp.app/Contents/Helpers"
Great, right? Yup, great, until the user runs something else that wants to set their PATH, it creates ~/.bash_profile, and this overrides your setup. After that, your executable will be in the PATH of zsh and ksh, but not bash. Whee.
And then one day the user decides to use tcsh instead, and it (and csh) have a completely different but equally messy pile of possible init files...

OS X GUI Cocoa app interacting with shell

Background:
We are developing an in house use only cocoa app to help us with some basic sysadmin tasks and complex website deployments. This application is basically a wrapper around many different bash shell commands. The output from these commands will sometimes need to parsed or displayed to the user.
We have played around with NSTask and are able to launch some scripts. However, this seems somewhat cumbersome (needing to set the exact path, passing in each argument separately, etc...). We can use NSTask in this way if this is actually the preferred method.
The biggest challenge so far is setting up the shell environment. We interact with many ruby gems and programs and deploy using capistrano.
The Question is:
How can we interact with the shell with an environment setup like a user? (aliases, rvm, ruby, paths)
The environment variables you'll see set in your shell in Terminal.app are pretty much confined to whatever shell you're using in the Terminal context. It's not picked up by "NSTask" automagically.
But... you do have options. Some of them are described in answers to this related question.
You can set more universal environment variables that do get picked up by NSTask via the "~/.launchd.conf" file, or you can set the shell of "NSTask" to match the one in Terminal (which means you pick up .bashrc or .profile or whatever initializes paths) via "[NSTask setLaunchPath:]" (where the launch path is your shell).
And of course you can also call "system()" from within your tools. This may also pick up the variables set in the "~/.launchd.conf" file.
More information on environment variables is available in this question.

Build and Debug application outside the default package

If I try to build an application with the application class outside the default package, so the application file path is /app/AppClass.mxml instead of /AppClass.mxml (as would normally be the case), Flash builder cannot launch the application for debugging because it is looking for the SWF in debug/app/AppClass.swf and the SWF is being output to debug/AppClass.swf instead. Changing the output folder to debug/app makes it put the swf in debug/app, but then it puts the application configuration file "AppClass-app.xml" in /debug/app/app and then that can't be found.
Is there a way to change only the SWF output folder, or the location of the xml configuration file in the run-configuration?
You may use symbolic link to created swf file - http://en.wikipedia.org/wiki/Symbolic_link
for example for Windows :
cd project/path/bin-debug/package/path/
MKLINK ClassName.swf project/path/bin-debug/ClassName.swf
and it's work
or you can use symbolic link for folder:
cd project/path/bin-debug/package/
MKLINK path project/path/bin-debug/ /D
I think I remember this worked for me. But it was long time ago. And, yes, it is a known problem, I also recall Adobe people mentioning it as a limitation of FB.
In my Ant script, you'll need to do the adjustments to reflect your actual file names and directory structure. Also note that it will make it more cumbersome to debug it from FB. You'll need to use the debugging target in Ant, and then connect the debugger to the running application (so that some info, especially on the startup) will be lost. The only way you would be able to debug it, though I've never tried it, is with the commandline tools (I'm not sure of adl syntax for breakpoints / printing / stack frames, so idk how to do it.
Also, for the released application you will probably want to change the signing mechanism.