@@ -4,14 +4,34 @@ set -euo pipefail
44# mac-mp4-screen-rec — Automatically convert macOS screen recordings and other video files
55# https://github.com/arch1904/MacMp4ScreenRec
66
7- VERSION=" 1.2.0"
7+ resolve_tool_path () {
8+ local tool_name=" $1 "
9+ local resolved_path
10+
11+ resolved_path=" $( command -v " $tool_name " 2> /dev/null || true) "
12+ if [ -n " $resolved_path " ]; then
13+ echo " $resolved_path "
14+ return 0
15+ fi
16+
17+ for resolved_path in " /opt/homebrew/bin/${tool_name} " " /usr/local/bin/${tool_name} " ; do
18+ if [ -x " $resolved_path " ]; then
19+ echo " $resolved_path "
20+ return 0
21+ fi
22+ done
23+
24+ echo " "
25+ }
26+
27+ VERSION=" 1.2.1"
828CONFIG_DIR=" ${HOME} /.config/mac-mp4-screen-rec"
929CONFIG_FILE=" ${CONFIG_DIR} /config"
1030RETENTION_DIR=" ${CONFIG_DIR} /retention"
1131PLIST_NAME=" com.mac-mp4-screen-rec.agent"
1232PLIST_PATH=" ${HOME} /Library/LaunchAgents/${PLIST_NAME} .plist"
13- FFMPEG=" $( command -v ffmpeg 2> /dev/null || echo " " ) "
14- FFPROBE=" $( command -v ffprobe 2> /dev/null || echo " " ) "
33+ FFMPEG=" $( resolve_tool_path ffmpeg) "
34+ FFPROBE=" $( resolve_tool_path ffprobe) "
1535CLEANUP_INTERVAL_SECONDS=3600
1636_video_codec_map_inputs=()
1737_video_codec_map_outputs=()
@@ -620,6 +640,24 @@ service_is_loaded() {
620640 [ -f " $PLIST_PATH " ] && launchctl list " $PLIST_NAME " & > /dev/null
621641}
622642
643+ service_state () {
644+ if ! service_is_loaded; then
645+ echo " stopped"
646+ return 0
647+ fi
648+
649+ launchctl print " gui/$( id -u) /${PLIST_NAME} " 2> /dev/null | sed -n ' s/^[[:space:]]*state = //p' | head -1
650+ }
651+
652+ service_last_exit_code () {
653+ if ! service_is_loaded; then
654+ echo " "
655+ return 0
656+ fi
657+
658+ launchctl print " gui/$( id -u) /${PLIST_NAME} " 2> /dev/null | sed -n ' s/^[[:space:]]*last exit code = //p' | head -1
659+ }
660+
623661read_marker_field () {
624662 local marker=" $1 "
625663 local field=" $2 "
@@ -692,6 +730,11 @@ generate_plist() {
692730 <string>$( command -v mac-mp4-screen-rec || echo " $0 " ) </string>
693731 <string>convert</string>
694732 </array>
733+ <key>EnvironmentVariables</key>
734+ <dict>
735+ <key>PATH</key>
736+ <string>/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
737+ </dict>
695738 <key>WatchPaths</key>
696739 <array>
697740${watch_paths} </array>
@@ -1188,10 +1231,22 @@ cmd_stop() {
11881231}
11891232
11901233cmd_status () {
1191- if service_is_loaded; then
1192- echo " service: running"
1193- else
1234+ local state exit_code
1235+ state=" $( service_state) "
1236+ exit_code=" $( service_last_exit_code) "
1237+
1238+ if [ " $state " = " stopped" ]; then
11941239 echo " service: stopped"
1240+ elif [ " $state " = " not running" ]; then
1241+ if [ -n " $exit_code " ]; then
1242+ echo " service: loaded (idle, last exit ${exit_code} )"
1243+ else
1244+ echo " service: loaded (idle)"
1245+ fi
1246+ elif [ -n " $exit_code " ]; then
1247+ echo " service: ${state} (last exit ${exit_code} )"
1248+ else
1249+ echo " service: ${state} "
11951250 fi
11961251 echo " "
11971252 cmd_list
0 commit comments