Last active
August 23, 2022 15:55
-
-
Save BB9z/b913b30c1bca61bfa53d144ecce107f0 to your computer and use it in GitHub Desktop.
Reveal the Latest Simulator Application’s Data Container in Finder.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Required parameters: | |
# @raycast.schemaVersion 1 | |
# @raycast.title Simulator Data Container | |
# @raycast.mode compact | |
# Optional parameters: | |
# @raycast.icon 🤖 | |
# @raycast.packageName com.github.bb9z.lo-sh | |
# Documentation: | |
# @raycast.description Reveal the Latest Simulator Application’s Data Container in Finder. | |
# @raycast.author bb9z | |
# @raycast.authorURL https://gist.github.com/BB9z/b913b30c1bca61bfa53d144ecce107f0 | |
cd ~/Library/Developer/CoreSimulator/Devices/ | |
isVaildDeviceDir () { | |
# echo $1 | |
# $1 is not directory or empty | |
if ! [[ -d "$1" ]] || ! [[ -n "$1" ]] ; then | |
return 1 | |
fi | |
device_type=$(/usr/libexec/PlistBuddy -c "Print :deviceType" "$1/device.plist") | |
# Skip apple watch device | |
if [[ $device_type == com.apple.CoreSimulator.SimDeviceType.Apple-Watch* ]]; then | |
return 1 | |
fi | |
return 0 | |
} | |
for f in $(ls -t) | |
do | |
if isVaildDeviceDir "$f"; then | |
break | |
fi | |
done | |
cd "$f" | |
device_dir=$PWD | |
echo "$device_dir" | |
device_type=$(/usr/libexec/PlistBuddy -c "Print :deviceType" "device.plist") | |
device_name=$(/usr/libexec/PlistBuddy -c "Print :name" "device.plist") | |
echo "The latest updated iOS device is: $device_name ($device_type)" | |
# Find latest app bundle dir | |
cd "$device_dir/data/Containers/Bundle/Application" | |
app_bundle_dir=$(ls -t|head -1) | |
if [[ -z "$app_bundle_dir" ]]; then | |
echo "Seems ths device doesnt have any application instead. $PWD" | |
exit 1 | |
fi | |
# Get the bundle, and id | |
cd "$app_bundle_dir" | |
app_bundle_dir= | |
for f in $(ls) | |
do | |
if [[ "$f" == *.app ]]; then | |
app_bundle_dir="$f" | |
fi | |
done | |
if [[ -z "$app_bundle_dir" ]]; then | |
echo "Cannot find a application bundle at $PWD" | |
exit 1 | |
fi | |
cd "$app_bundle_dir" | |
app_bundle_dir=$PWD | |
app_bundle_id=$(/usr/libexec/PlistBuddy -c "Print :CFBundleIdentifier" "Info.plist") | |
echo "The latest updated application is: $app_bundle_id @$app_bundle_dir" | |
if [[ -z "$app_bundle_id" ]]; then | |
echo "Error: invaild bundle id" | |
exit 1 | |
fi | |
# Find the right data container | |
cd "$device_dir/data/Containers/Data/Application" | |
isContainerForID() { | |
if ! [[ -n "$1" ]] || ! [[ -n "$2" ]] ; then | |
return 1 | |
fi | |
local metadata="$1/.com.apple.mobile_container_manager.metadata.plist" | |
if ! [ -f "$metadata" ]; then | |
return 1 | |
fi | |
local current_id=$(/usr/libexec/PlistBuddy -c "Print :MCMMetadataIdentifier" "$metadata") | |
if ! [[ "$current_id" == "$2" ]]; then | |
return 1 | |
fi | |
return 0 | |
} | |
for f in $(ls -t) | |
do | |
if isContainerForID "$f" "$app_bundle_id"; then | |
cd "$f" | |
echo "The latest application’s data container is: $PWD" | |
open "$PWD" | |
exit 0 | |
fi | |
done | |
echo "Cannot find the latest application’s data container." | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script has a problem if the app name has a space in it. In my fork I made a quick fix.