PDA

View Full Version : Question: Run shell script from an icon?


KennX
08-11-2007, 01:48 AM
How would I go about running a shell script from an icon? I tried just making an xyz.app folder and then renaming the .sh script as .app inside of it but when I click on the icon I just see the blank (default icon) screen and nothing happens. I set up everything in the folder like it seemed the other apps were set up. Any help would be greatly appreciated!

-KennX

tendo
08-11-2007, 02:27 AM
you need to make an app that calls that .sh script. not just package and .sh script

bram
08-11-2007, 08:24 AM
OS X (and of course NeXT) applications aren't actually a simple executable, but rather a directory structure. Look inside the other apps, and you will see an executable, with other files and possibly other directories. Some of those files, such as Info.plist, are required to be there.

So you can create 'My.app', and populate it with the necessary files (look at 3rd party apps other people have made, or SSH to your iPhone, and look through the /Applications/) folder).

As for executing the shell script, I can imagine two ways to do it. I believe that OS X will execute anything that has the executable flag set. So you should in theory be able to simply put the shell script in the directory, make sure you do 'chmod 755' on it, and then edit the Info.plist, edit the Key CFBundleExecutable to use its name, and it should work.

If that doesn't work, you could also write a small C program like:

#include <stdlib.h>

int main(int argc, char **args) {
system("myshell.sh");
}

KennX
08-12-2007, 12:13 AM
THANKS!!! I tried the first approach (putting the .sh in the CFBundleExecutable) and it worked like a charm. I am putting up a desktop switcher script/app on modmyiphone.com as well as linked off of my Blog:

http://digestingreality.blogspot.com/2007/08/iphone-iswap-application.html

If anyone else is interested in it.

Thanks to your help!

-KennX