Created
December 9, 2025 12:04
-
-
Save nurimelih/4235a6c223938770260d8006df3f9b78 to your computer and use it in GitHub Desktop.
Open Realm DB in Realm Studio for active iOS Simulator
This file contains hidden or 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
| # Realm DB - find and open for active iOS simulator | |
| # Usage: Add to ~/.zshrc, then run: source ~/.zshrc && realm-open | |
| realm-open() { | |
| local booted=$(xcrun simctl list devices booted -j | python3 -c " | |
| import sys,json | |
| d=json.load(sys.stdin) | |
| sims=[(u['name'],u['udid']) for devs in d['devices'].values() for u in devs if u.get('state')=='Booted'] | |
| for name,udid in sims: print(f'{name}|{udid}') | |
| ") | |
| local count=$(echo "$booted" | grep -c '|') | |
| if [[ $count -eq 0 ]]; then | |
| echo "No booted simulator found" | |
| return 1 | |
| elif [[ $count -eq 1 ]]; then | |
| local udid=$(echo "$booted" | cut -d'|' -f2) | |
| else | |
| echo "Select simulator:" | |
| local i=1 | |
| echo "$booted" | while read line; do | |
| echo " $i) $(echo $line | cut -d'|' -f1)" | |
| ((i++)) | |
| done | |
| read "choice?Enter number: " | |
| local udid=$(echo "$booted" | sed -n "${choice}p" | cut -d'|' -f2) | |
| fi | |
| local realm_file=$(find ~/Library/Developer/CoreSimulator/Devices/$udid -name "*.realm" 2>/dev/null | head -1) | |
| if [[ -n "$realm_file" ]]; then | |
| echo "Opening: $realm_file" | |
| open -a "Realm Studio" "$realm_file" | |
| else | |
| echo "No realm file found" | |
| fi | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment