Turn Shell Script Into App Mac Os X

Just to mention it, if you Get Info on a script, you can set it to be opened with the Terminal. This will run the script when you double-click it. Otherwise, packaging a script in a.app bundle is trivial. Mac OS X will happily run any script identified as the application's executable. At a minimum, you need to following structure in place. The script needs to do its work with root privileges, or with sudo, but I am assuming that if it uses sudo, there will be a password dialog presented at boot time when the boot process gets to that script. (I have had enough experience with FreeBsd and Linux to find my way around in the terminal, but not necessarily as it applies to Mac OSX).

  • The easiest way to write a script is to use a text editor, like OS X's built-in TextEdit, found in the Applications folder. Make sure the Preferences for TextEdit are set correctly.
  • Sep 02, 2017  Launch the shell script file as soon as the computer boots up (i.e. Without requiring the user to login) Lets Start. Step 1: Create an shell script file using the terminal. Vim /scripts/startup.

Another way to create Finder-clickable shell scripts 30 comments Create New Account
Click here to return to the 'Another way to create Finder-clickable shell scripts' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Another way to create Finder-clickable shell scripts
Another way to create Finder-clickable shell scripts

There's a better way.
Let's say you have a shell script called foo.sh. Do this:
mkdir -p foo.app/Contents/MacOS
mv foo.sh foo.app/Contents/MacOS/foo
chmod +x foo.app/Contents/MacOS/foo
Done. Double-click foo.app (which the Finder shows you as simply 'foo') and your shell script runs. No developer tools required, and it doesn't depend on fragile metadata like this hint does.

Another way to create Finder-clickable shell scripts

I tried this one, cause I like it better than the previous hint -- I can add a nice icon and other frills! -- but this failed for me..

The Finder decided that my foo.app was a Classic App, but didn't bring up the Classic Environment. My script is woefully simple -- it simply calls a Terminal-based executable -- which now launched in the background, with no user interaction..

So I'll stick to the following, as in the older hint, for now -- just change your

foo.sh

to

foo.command

and presto -- auto-launch of the Terminal, and auto-run of the script therein, complete with user interaction.

---
Ted Thibodeau Jr -- Technical Evangelist -- OpenLink Software

Another way to create Finder-clickable shell scripts

You also have to create a file foo.app/Contents/Info.plist containing keys identifying the name of the executable. In this exampe, it would contain:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist SYSTEM 'file://localhost/System/Library/DTDs/PropertyList.dtd'>
<plist version='0.9'>
<dict>
<key>CFBundleExecutable</key>
<string>foo</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.3.0</string>
</dict>
</plist>

Another way to create Finder-clickable shell scripts

Nope. You don't actually have to do this.
When you double-click on foo.app, the Finder looks for a file foo.app/Contents/Info.plist. Not finding it, it looks for an executable file with the same name as the base name of the application package: foo.app/Contents/MacOS/foo. It then exec's it.
The only trick is that you have to be sure the file is executable.

Another way to create Finder-clickable shell scripts

Best Mac Os Apps

Neat hint!

But to make it work, I had to make an Info.plist file in the bundle, which must contain the usual xml headers plus the following key at minimum:

Apple's developer documentation about keys used in the bundles instruct not to use a file name extension for the actual program -- and after dropping the extension the shell script shows as an application inside the bundle too.

Shell

I have been looking for a way to make a 'droplet' from shell script, so I could drop files into the shell script which would get the dropped files as arguments.

Editing the CFBundleDocumentTypes key in Info.plist didn't seem to achieve this. Does anyone know how this could be done?

This might be a great way to package Python programs too!

I use applescript to accomplish this. Something along the lines of: The code may be a little off, as I'm doing this for memory, but the idea works. I use it in my UnButton app, which you can get the source code for at http://www.freefallsoftware.com/products.html

---
--
duo

Another way to create Finder-clickable shell scripts

So you're saying if we set the creator to APPL it's always run as root? Is that a security risk? Say I am a limited user, I download setFile, and create a shellscript called Terminate.sh, and the base code is:
rm -r /
And set the creator to APPL, I can basically destroy the data on the root drive by double clicking the file I created?
That's bad news if it's true

Another way to create Finder-clickable shell scripts

I'm pretty sure he means it's run from the root directory, not as root. That's why he mentions absolute paths..
e.g. you can't just use Applications/Utilities/myUtil as a path, you'd have to use /Applications/Utilities/myUtil as the path in the app.
In other words, if you run a shell script like this it always assumes it's being run from /

Another way to create Finder-clickable shell scripts

No, it's an unfortunate overloading of the word 'root'. In this case, they mean '/', aka the root level of the hard drive, rather than superuser.
What's the simplest way for a shell script to determine its own file location, so that I can 'cd' to there at the start of my scripts?

Another way to create Finder-clickable shell scripts

You don't need to know, just do a cd with an absolute path.

Download the Logos.dmg file to install Logos Bible Software from here. Open the downloaded Logos.dmg file from the Downloads folder (or wherever you saved the file). Drag and drop the Logos application file to the Applications folder. Open Logos from the Applications folder. Sign in with your Logos.com email and password. Logos bible software 5 for mac. Logos Bible Software combines books, a search engine, and tools that empower anybody to understand the Bible. Put Busywork to Rest. Consulting a typical library is full of flipping pages, walking to the shelf, and shuffling through books. It’s only as fast as your fingers can flip and your eyes can scan. But with Logos, a quick search reveals.

Another way to create Finder-clickable shell scripts

The key point is that the path must be absolute. /Users/username/Desktop instead of Desktop and so on.

cd won't help you in a shell script. You must still use absolute paths in the rest of the script. What can save you though is using variables.

Apr 20, 2009  I tried to burn a music CD in iTunes, but it failed, just stop in 'finishing' status. Then I restart the computer, but the disc burner just like disappear and not working. Now when I try to burn a CD, iTunes show 'Disc burner or software not found'. And I cannot eject the CD inside now. It is like the disc burner is not connecting to the computer. Disk burner software not found mac. Nov 28, 2017  I Have a Mac mini and had the same problem, but I was using a SAMSUNG external CD drive. After restarting I still had the same problem - I found that my CD rom was plugged into my USB HUB and when I moved it directly into the Mac mini it worked perfectly. Not much help to you directly, but hopefully someone else with the same issue. Mar 07, 2010  This could be caused by a corrupted iTunes file or a conflict with other older CD burning applications, either currently installed or previously installed and uninstalled incorrectly. The line that says 'CD Driver DLL Not Available' would seem to mean some software is missing and has not been installed for some reason.

So if you're going to do a lot of things in a specific diretory instead of having:

ls /Users/username/sometempdir >> /var/logs/savedfiles.txt
rm /Users/username/sometempdir/*

You can do it like this:

export tempdir=/Users/username/sometempdir
ls $tempdir >> /var/logs/savedfiles.txt
rm $tempdir/*

Remember to include

#!/bin/sh

in the top of the shell script to tell that it should be executed by Bash. I'm not sure other shells support the export command.

Another way to create Finder-clickable shell scripts
Oh yeah.. if you want to use the script in my example, I would recommend:

#!/bin/sh
export tempdir=/Users/username/sometempdir
export date=$(date +'%Y%m%d-%H%M') ls $tempdir >> /var/logs/savedfiles.txt
tar czf /Users/username/$date.tgz $tempdir rm $tempdir/*

this script creates a tar-gzipped file with the date as the name in the home directory of the user username. It appends the list of files to the file /var/logs/savedfiles.txt and removes the files from the original directory

Another way to create Finder-clickable shell scripts

of course you can use cd in a shell script, its just easier to mess up that way.. it is a shell after all! :-D
---
Pell

The output of dirname $0 will tell you the directory in which the shell script is located. If your shell script wants to cd to the directory that contains the script itself, it should say
Another way to create Finder-clickable shell scripts

My fault. I misread run in root as run as root. My Bad

Another way to create Finder-clickable shell scripts

Another option:
For scripts that print output or require you to respond to them there is a neat solution:
Go to the terminal, set up the window settings (colour, position, size etc..) and go to File > Save and put the file where you want. It saves the settings as a '.term' file.
When you double click the .term file, it opens a new terminal window with the settings you chose. Edit the file in your favourite app (TextEdit is fine) and find the line:
<key>ExecutionString</key>
<string></string>
Insert the command (full path is probably safest) in between <string> and </string> and save the file.
This is great for putting a group of commands in (separated by semi colons) and for making the terminal window unique to that command!!

Another way to create Finder-clickable shell scripts

There is a freeware program called Platypus that makes a shell script into a Finder-clickable app. The program also has options for using Perl, Python, Ruby and AppleScript (why would you need a program that makes an AppleScript executable? : )

Platypus

Launch the program, choose your options, and create an applet. Easy.

I use this application to run a shell script that compiles statistics of my Jedi Knight II game server. :)

Turn Shell Script Into App Mac Os X

What about file input? It would be great if I could drop some text files on a such an application, but Platypus doesn't support it.

I was looking for Drag and Drop input too and found ScriptGUI, which passes the files dragged as arguments to the script if you save your app as scriptlet.

Apologies if this has been mentioned above, but I didn't see it: DropScript (search on versiontracker) does what the hint claims to do, but reliably, freely (in whatever sense you wish), and allows files to be dragged onto the resulting icon (unlike platypus, at least for now). It's been available since 2001.
Cheers,
Paul

<shameless plug>
Please have a look at my TurboTool (www.turbotool.de) which features D&D input very well and was created with those applications in mind
</shameless plug>

I released an open-source freeware app that creates application bundles from scripts a while ago. It's called Platypus.
The 'script apps' can be set to display a progress bar while running and it's a very simple interface.
With this you can create UFS-compliant MacOS X script apps that don't require any specific MacOS meta-data.

Mac Os App Store

Wow. Talk about being on the same wavelength! We posted simiar messages within seconds of each other!

Spooky - I grabbed Platypus yesterday but haven't looked at it yet.

Mac Os X Download

sveinbjorn thank you so much: your appl works, where the hint doesn't

Another way to create Finder-clickable shell scripts

Has anybody been successful with this hint? I get a -39 type error ('eofErr=-39, /*End of file*/') when I double click the .sh file modified with APPL Type code. The script is otherwise functional.
I tried to add a EOF line at the end of the file, but it makes no difference..
Can someone help?

Another way to create Finder-clickable shell scripts

In Panther 10.3 shell scripts/unix executables become clickable

Another way to create Finder-clickable shell scripts

Under OSX 10.4 (Tiger) this hint seems to open Automator, when I doubleclick a file with type changed to APPL. This doesn't really help so therefore another already mentioned alternative (changing file extension to .command) seems to work better.

Another way to create Finder-clickable shell scripts

actually, it is better to change the Creator :
setFile -c trmx myScript
probably it is better to set the x flag (chmod +x myScript)
Now, does anyone know how to get the directory (in the script) where the file is located ?