|
1 | 1 | #!/bin/bash |
2 | | -echo "📹 Opening QuickTime..." |
3 | | - |
4 | | -osascript <<EOD |
5 | | -tell application "QuickTime Player" |
6 | | - activate |
7 | | - set newMovieRecording to new movie recording |
8 | | -end tell |
9 | | -
|
10 | | -tell application "System Events" to tell process "QuickTime Player" |
11 | | - click button 3 of window 1 |
12 | | -end tell |
13 | | -return |
| 2 | +LOCATION=$(dirname "$0") |
| 3 | +source "$LOCATION"/../common_tools |
| 4 | +IOS_DEVICES_LIST=$LOCATION/../data/toolkit_recordable_ios_devices.txt |
| 5 | +trap 'ctrlc $@' 1 2 3 6 15 |
| 6 | + |
| 7 | +RECORDING=false |
| 8 | +cd ~/Desktop || exit |
| 9 | + |
| 10 | +ctrlc(){ |
| 11 | + if $RECORDING ; then |
| 12 | + echo "✅ Saved into ~/Desktop/$FILENAME" |
| 13 | + fi |
| 14 | + osascript -e 'quit app "QuickTime Player"' |
| 15 | + exit |
| 16 | +} |
| 17 | + |
| 18 | +check_videosnap_dependency(){ #TODO refactor when videosnap available via Homberew |
| 19 | + if ! [ -x "$(command -v "videosnap")" ]; then |
| 20 | + echo "💥 \"videosnap\" command required!" |
| 21 | + should_proceed "🛒 Install via GitHub? (download and run \"videosnap-0.0.6.pkg\")" |
| 22 | + open "https://github.com/matthutchinson/videosnap/releases" |
| 23 | + exit 1 |
| 24 | + fi |
| 25 | +} |
| 26 | + |
| 27 | +start_quicktime(){ |
| 28 | + echo "💡 Starting QuickTime to enable recording (webcam light might turn on)..." |
| 29 | + osascript <<EOD |
| 30 | + tell application "QuickTime Player" |
| 31 | + set newMovieRecording to new movie recording |
| 32 | + set miniaturized of window 1 to true |
| 33 | + end tell |
14 | 34 | EOD |
| 35 | +} |
| 36 | + |
| 37 | +pick_recording_device(){ |
| 38 | + echo "⏳ Detecting iOS devices..." |
| 39 | + rm -f "$IOS_DEVICES_LIST" |
| 40 | + videosnap -l >> "$IOS_DEVICES_LIST" |
| 41 | + grep -E -v "Found|FaceTime" "$IOS_DEVICES_LIST" > "$IOS_DEVICES_LIST.tmp" #remove info line and webcam |
| 42 | + mv "$IOS_DEVICES_LIST.tmp" "$IOS_DEVICES_LIST" |
| 43 | + sed 's/^* //g' "$IOS_DEVICES_LIST" > "$IOS_DEVICES_LIST.tmp" #remove "* " line prefixes |
| 44 | + mv "$IOS_DEVICES_LIST.tmp" "$IOS_DEVICES_LIST" |
| 45 | + |
| 46 | + if [ "$(nl "$IOS_DEVICES_LIST")" == "" ]; then |
| 47 | + echo "❌ iOS device not detected, reconnect it and try again" |
| 48 | + ctrlc |
| 49 | + fi |
| 50 | + |
| 51 | + if [ "$(wc -l "$IOS_DEVICES_LIST" | awk '{print $1}')" == "1" ]; then |
| 52 | + DEVICE_NAME="$(cat "$IOS_DEVICES_LIST")" |
| 53 | + else |
| 54 | + echo "📱 Available:" |
| 55 | + nl "$IOS_DEVICES_LIST" |
| 56 | + read -r -p "📝 Choose: " DEVICE_INDEX |
| 57 | + |
| 58 | + DEVICE_NAME=$(sed "$DEVICE_INDEX"!d "$IOS_DEVICES_LIST") |
| 59 | + if [[ $DEVICE_INDEX == "" || $DEVICE_NAME == "" ]]; then |
| 60 | + delete_lastline |
| 61 | + pick_recording_device |
| 62 | + fi |
| 63 | + fi |
| 64 | +} |
| 65 | + |
| 66 | +start_recording(){ |
| 67 | + RECORDING=true |
| 68 | + FILENAME="$DEVICE_NAME-$(date +%Y-%m-%d-%H-%M-%S).mp4" |
| 69 | + echo "📹 Recording screen on $DEVICE_NAME, stop it with ctrl^c" |
| 70 | + videosnap -w 0 -p High -d "$DEVICE_NAME" "$FILENAME" &> /dev/null |
| 71 | +} |
| 72 | + |
| 73 | +check_videosnap_dependency |
| 74 | +start_quicktime |
| 75 | +pick_recording_device |
| 76 | +start_recording |
0 commit comments