simple mac app bundle with embeded media files
By JIMz
current state
Having dozens of mini reaper projects while doing N3 studies, want to organize them as mac app bundle for easier maintenance.
desired state
each mini reaper project as a self-contained mac app bundle with all media files grouped inside, double-click and the project file will be called by reaper.
tried but failed methods
- creating a folder with a
.app
extension, with the following structure :
[folder name].app
Contents/
MacOS/
Info.plist
- manually crafted the content of
Info.plist
with the followings :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>MyScript.sh</string>
<key>CFBundleIdentifier</key>
<string>com.example.MyFolder</string>
<key>CFBundleName</key>
<string>MyFolder</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
</dict>
</plist>
- with a script file like :
#!/bin/zsh
open -a [app name] "/path/to/[app project]"
- modify
Info.plist
to run the script file, which call the project file accordingly
but keep having different errors.
alternative approach that worked
1. create a simple apple application with automator
- create an application ;
- in the left panel, choose
actions
; - in the search box, type
run
; - firstly, add
Run AppleScript
; - then, add
Run Shell Script
;- i.e. the
Run AppleScript
section should run first, the output from it will be fed as input for the next sectionRun Shell Script
; - in the
Run Shell Script
box, on the top-right pull down menu, chooseas arguments
;- configured this way, the output from the applescript will be regarded as “$1” by the shell script ;
- i.e. the
2. add custom scripts
appleScript
in the appleScript section, add these :
on run {input, parameters}
-- Get the path of the running application bundle
set appBundlePath to POSIX path of (path to (current application) as text)
-- Pass the app bundle path as input to the next step
return appBundlePath
end run
- what these do is simply providing the path to this app bundle at the time of running
- tried using shell script to get this info but none of the following works :
# all failed :
pwd
dirname
${BASH_SOURCE}
${BASH_SOURCE[0]}
in which :
pwd
will only output value equivalent to"$HOME"
;- all other command will only output
"."
;
shell script
in the shell script section, add these :
#!/bin/zsh
LOG="$HOME/Desktop/app.log"
echo "-----------------------" | tee -a "$LOG"
echo "app started : $( date )" | tee -a "$LOG"
# from applescript, get the current running application location
PATH_THIS_APP="$1"
# construct other vars accordingly
PATH_REAPER_PROJECT="$PATH_THIS_APP"'Contents/reaper'
FILE_REAPER_PROJECT="$PATH_REAPER_PROJECT"/'reaper.rpp'
# define the path to target app
APP_REAPER="/Applications/REAPER.app"
# optional logs to file
echo "input from applescript : PATH_THIS_APP : $PATH_THIS_APP" | tee -a "$LOG"
echo "PATH_REAPER_PROJECT : $PATH_REAPER_PROJECT" | tee -a "$LOG"
echo "FILE_REAPER_PROJECT : $FILE_REAPER_PROJECT" | tee -a "$LOG"
# run the app
echo "run the reaper project file now ... " | tee -a "$LOG"
open -a "$APP_REAPER" "$FILE_REAPER_PROJECT"
# make the end, this will be logged without waiting for the above opened app to end
echo "app ended : $( date )" | tee -a "$LOG"
notes :
- app bundle running path provided by appleScript as
"$1"
; - path to related application can be found via terminal ;
- open the app via
open -a [path to app] [path to app file]
3. draw back / to be optimized
- size
- original archive : around 1.5 MB
- app bundle with icon file : around 6 MB
- mainly owing to ( both under
[app bundle root]/Contents/Resources/
) :ApplicationStub.icns
: 1.6 MBAssets.car
: 1.5 MB
- mainly owing to ( both under
- i.e. this approach by creating a minimal apple application to modify on guarantee to be running properly, but gaining some additional weight in file sizes ;
- will be revised later on to see if these are inevitable or can be trimmed ;
- icon file
- the app bundle comes with the icon file in
[app bundle root]/Contents/Resources/ApplicationStub.icns
- the icon file, when opened with Preview, contains different sizes of the same image, the appearance is optimized by zoom level ;
- currently, the icon file is manually assigned by copying an image file to the info icon ;
- next step to see how to build a customized icon file of the same
.icns
format ;
- mixin appleScript
- not very ideal but got no choice at the meantime before a shell-native solution can be found ;