The currently accepted answer does not quite work for me. I get the little broken application icon.
The following works for me under OSX 10.15.7 (Catalina). You can feel free to change the YourApplication
in all of the following instructions to be the name you really want.
mkdir a directory with the .app
extension in the /Applications
folder with a Contents
and then MacOS
subdirectories.
mkdir -p /Applications/YourApplication.app/Contents/MacOS
Move your script into this directory and name it the same as the top application folder but without the .app
extension and without the shell script extension:
mv yourscript.sh /Applications/YourApplication.app/Contents/MacOS/YourApplication
Make sure your script is executable:
chmod +x /Applications/YourApplication.app/Contents/MacOS/YourApplication
Here's a sample application to try:
#!/bin/sh
result=`osascript -e 'display dialog "Should I beep?" buttons {"Yes", "No"}'`
if [[ "$result" = "button returned:Yes" ]]; then
osascript -e 'beep'
fi
Your application should now be ready and the script should run when you double click on it. It's important to note that if you rename the application, you will need to rename the underlying script.
To have your application seen by LaunchPad was harder to figure out. The following seemed to work. You need to add something like the following into the /Applications/YourApplication.app/Contents/Info.plist
file. You might also need to move it over to a DMG file and back to Applications for LaunchPad to notice it. See: https://stackoverflow.com/a/71342335/179850
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>My App</string>
<key>CFBundleGetInfoString</key>
<string>My App 1.0</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
</dict>
</plist>
To add an icon to your new application, you need to do the following:
Find or create a PNG that you want to be your icon.
Open the image in the Preview application – other graphics apps may also work.
Press command-a to select all and then command-c to copy it to the clipboard.
Select your application in the Finder and press command-i to Get Info window.
Click on the icon in the upper left corner of the info window to select it:
Paste the image from the clipboard which should change the icon.
You can also open up the Get Info window on other application, select it's icon, and copy it so you can paste it onto your new application. After you assign any icon, if you look in your .app
directory, you should see a filename that starts with Icon
.
#!/bin/bash ; say "Hi" ; exit 0
(With each of the commands on different lines, and w/o the semicolon).