Guest User

Untitled

a guest
Jan 18th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Starts and stops recording in the simulator
  4.  
  5. # Set your prefered output directory here
  6. outputDirectory=~/Desktop/
  7.  
  8. # Open recordings in the default app when ending recording
  9. openRecordings=true
  10.  
  11. # Choose whether to play sounds when starting and stopping a recording
  12. playSounds=true
  13.  
  14. # Edit the format of the filename. By default it saves files with names like `Simulator 2019-01-04 at 10.16.21.mp4`
  15. # do not add an extension to the below variable, `.mp4` will be added further down.
  16. filename="Simulator "$(date '+%Y-%m-%d at %H.%M.%S')
  17.  
  18. tmpPathPrefix="/tmp/com.alexjsp.simulator-recording."
  19. recordingPathVarStoragePath="$tmpPathPrefix""recordingPath.txt"
  20. gifPathVarStoragePath="$tmpPathPrefix""gifPath.txt"
  21. recordingPIDVarStoragePath="$tmpPathPrefix""recordingPID.txt"
  22.  
  23. function notify {
  24. # If running in an interactive terminal then echo status notifications,
  25. # otherwise post a system notification.
  26. if [ -t 0 ]; then
  27. echo $1
  28. else
  29. osascript -e 'display notification "'"$1"'" with title "Simulator Recording"'
  30. fi
  31. }
  32.  
  33. if [ -f $recordingPathVarStoragePath ] && [ -f $recordingPIDVarStoragePath ]; then
  34. # Stop existing recording
  35. read recordingPath < $recordingPathVarStoragePath
  36. read recordingPID < $recordingPIDVarStoragePath
  37. read gifPath < $gifPathVarStoragePath
  38. rm "$tmpPathPrefix""recordingPath.txt"
  39. rm "$tmpPathPrefix""gifPath.txt"
  40. rm "$tmpPathPrefix""recordingPID.txt"
  41. notify "Stopping recording..."
  42. if [ "$playSounds" = true ] ; then
  43. afplay /System/Library/Sounds/Purr.aiff > /dev/null 2>&1
  44. fi
  45. sleep 2
  46. kill -SIGINT $recordingPID
  47. sleep 2
  48.  
  49. /usr/local/bin/ffmpeg -nostdin -i "$recordingPath" -r 20 "$gifPath" > /dev/null 2>&1
  50.  
  51. sleep 1
  52.  
  53. rm "$recordingPath"
  54.  
  55. if [ "$openRecordings" = true ] ; then
  56. open "$outputDirectory"
  57. else
  58. notify "Recording saved to ""$gifPath"
  59. fi
  60.  
  61. else
  62. if ! pgrep -xq -- "Simulator"; then
  63. notify "Simulator doesn't appear to be running"
  64. if [ "$playSounds" = true ] ; then
  65. afplay /System/Library/Sounds/Basso.aiff > /dev/null 2>&1
  66. fi
  67. exit 1
  68. fi
  69.  
  70. # Start a new recording
  71. if [ "$playSounds" = true ] ; then
  72. afplay /System/Library/Sounds/Pop.aiff > /dev/null 2>&1
  73. fi
  74. recordingPath="$outputDirectory""$filename"".mp4"
  75. gifPath="$outputDirectory""$filename"".gif"
  76. xcrun simctl io booted recordVideo "$recordingPath" &
  77. echo $! > "$tmpPathPrefix""recordingPID.txt"
  78. echo $recordingPath > "$tmpPathPrefix""recordingPath.txt"
  79. echo $gifPath > "$tmpPathPrefix""gifPath.txt"
  80. notify "Started recording to ""$recordingPath"
  81. fi
Add Comment
Please, Sign In to add comment