Created
March 5, 2024 20:07
-
-
Save afsal-backer/42045e227615461ed7ce537f59cf8bc8 to your computer and use it in GitHub Desktop.
Remove media from Photos app
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/sh | |
# add_video_to_photos.sh | |
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
PARENT_DIR="$(dirname "$SCRIPT_DIR")" | |
# Set the log file path | |
LOG_FILE="${PARENT_DIR}/add_video.log" | |
# Redirect errors to the log file | |
exec >"$LOG_FILE" 2>&1 | |
# Set the desired simulator name | |
SIMULATOR_NAME="iPhone 15" | |
# Function to wait for the simulator to boot | |
wait_for_simulator_boot() { | |
local timeout=120 | |
local wait_time=0 | |
while [[ -z $(xcrun simctl list devices | grep -w "Booted") ]]; do | |
sleep 1 | |
((wait_time++)) | |
if [[ $wait_time -ge $timeout ]]; then | |
echo "Timed out waiting for the simulator to boot" | |
exit 1 | |
fi | |
done | |
} | |
# Read the SIMULATOR_UDID environment variable | |
SIMULATOR_UDID=$(xcrun simctl list devices | grep -w "Booted" | awk -F '[()]' '{print $2}') | |
# Check if the environment variable is set, and boot the simulator if not | |
if [[ -z $SIMULATOR_UDID ]]; then | |
SIMULATOR_UDID=$(xcrun simctl list devices | grep -w "Shutdown" | grep -m 1 "$SIMULATOR_NAME" | awk -F '[()]' '{print $2}') | |
if [[ -z $SIMULATOR_UDID ]]; then | |
echo "Failed to get the simulator ID" | |
exit 1 | |
fi | |
xcrun simctl boot "$SIMULATOR_UDID" | |
fi | |
# Call the function to wait for the simulator to boot | |
wait_for_simulator_boot | |
ENGLISH_VIDEO_PATH="${PARENT_DIR}/Assets/english.mp4" | |
# Check if the environment variable is set | |
if [[ -z $SIMULATOR_UDID ]]; then | |
echo "Failed to get the simulator ID" | |
exit 1 | |
else | |
echo "Simulator ID from bash is: $SIMULATOR_UDID" | |
fi | |
xcrun simctl addmedia "$SIMULATOR_UDID" "$ENGLISH_VIDEO_PATH" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment