Skip to content

Instantly share code, notes, and snippets.

@kallewoof
Last active September 2, 2015 08:04
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save kallewoof/de4899aabde564f62687 to your computer and use it in GitHub Desktop.
Shell script to symlink up links to all iOS apps in simulator. Depends on https://github.com/kallewoof/plget
#!/bin/bash
if [ ! -e ".appshfolder" ]; then
echo "Run this from the designated folder please."
echo "If this is the first time you run this script, this is recommended:"
echo " cd"
echo " mkdir iosapps"
echo " cd iosapps"
echo " touch .appshfolder"
echo " cp <path to app.sh> ."
echo " ./app.sh"
exit
fi
rm -f simulator
rm -f *.sdk
rm -f *.dr
rm -f *.iapp
blacklisted="DDActionsService MobileSafari StoreKitUIService Web WebContentAnalysisUI WebViewService"
dest=$PWD
ln -s ~/Library/Developer/CoreSimulator/Devices simulator
cd simulator
for uuid in *; do # uuid refers to some simulated device (e.g. iPhone 5S on iOS 8.1)
# Some devices have *no* applications; we don't care about them
if [ -d "$uuid/data/Applications" ] || [ -d "$uuid/data/Containers/Data/Application" ]; then
devtype=`plget $uuid/device.plist deviceType`
runtime=`plget $uuid/device.plist runtime`
devtype=${devtype:38} # trim out "com.apple.CoreSimulator.SimDeviceType."
runtime=${runtime:35} # trim out "com.apple.CoreSimulator.SimRuntime."
# we now have e.g. devtype = iPhone-5s and runtime = iOS-8-1
# we refer to this as "iOS-8-1_iPhone-5s"
drref="$runtime"_"$devtype"
# iOS 8 has: data/Containers/Data/Application/<app uuid>
# iOS < 8 has: data/Applications/[UUID]
ln -s simulator/$uuid/data $dest/$drref.dr
if [ -d "$uuid/data/Applications" ]; then
# iOS ..7
appfolder="Applications"
datfolder="Applications"
prevwd=$PWD
cd $uuid/data/"$appfolder"
for appdir in *; do
for appname in $appdir/*.app; do
if [ -e "$appname" ]; then
# We have "appdir/Some app.app" and we want "Some app"
# This also means this IS an app, and not e.g. '.' or '..' or something weird
appname=${appname:0:$((${#appname}-4))}
appname=${appname:${#appdir}}
include=1
for bl in $blacklisted; do
# appname has a leading / so we put one into the blacklisted entries too
if [ "/$bl" = "$appname" ]; then
include=
fi
done
if [ $include ]; then
if [ -e $dest/"$appname"-$drref.iapp ]; then
# The drref and app exist; which is very odd but happens
iter=2
while [ -e $dest/"$appname ($iter)"-$drref.iapp ]; do
let iter++
done
appname="$appname ($iter)"
fi
ln -s $drref.dr/"$datfolder"/$appdir $dest/"$appname"-$drref.iapp
fi
fi
done
done
cd "$prevwd"
else
# iOS 8..
# We parse the plist instead, but first we need to de-binarize it
prevwd=$PWD
cd "$uuid/data/Library/BackBoard"
if [ -e "applicationState.plist" ]; then
plutil -convert xml1 -o - applicationState.plist > plainas.plist
entries=`plget plainas.plist "*/compatibilityInfo/sandboxPath"`
rm plainas.plist
appid=
for e in $entries; do
# is this an app id or a sandboxPath? determined by whether * at start or not
if [ "${e:0:1}" = "*" ]; then
appid=${e:1}
elif [ "$appid" != "" ]; then
# this is a sandbox path; we ignore all "com.apple." app ids
if [ "${appid:0:10}" != "com.apple." ]; then
ln -s "$e" $dest/"$appid"-$drref.iapp
fi
fi
done
cd $prevwd
fi
fi
fi
done
cd $dest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment