英文:
Running Custom Bash Script Works in Terminal But Not RayCast
问题
I'm writing a Raycast bash script that converts the most recent Screen Recording into a Gif using this tool. The script is below. The line: ffmpeg -i "$recent_file" -pix_fmt rgb24 -r 10 -f gif - | gifsicle --optimize=3 --delay=3 > out.gif
works properly when run in Terminal. Unfortunately, it doesn't output out.mov
when run in Raycast, despite the fullOutput
of Raycast showing it completes as intended (see screenshot). Is there some kind of setting required in Raycast to allow the use of these command-line tools?
#!/bin/bash
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Gif Most Recent Screen Recording
# @raycast.mode fullOutput
# Optional parameters:
# @raycast.icon 🤖
# Documentation:
# @raycast.author willbeing
# @raycast.authorURL https://raycast.com/willbeing
directory="/Users/willbeing/Desktop/Screenshots" # Replace with your desired directory
# Check if the directory exists
if [ ! -d "$directory" ]; then
echo "Directory does not exist."
exit 1
fi
# Retrieve the most recent .mov file
recent_file=$(ls -t "$directory"/*.mov 2>/dev/null | head -n 1)
# Output the most recent .mov file
if [ -n "$recent_file" ]; then
ffmpeg -i "$recent_file" -pix_fmt rgb24 -r 10 -f gif - | gifsicle --optimize=3 --delay=3 > out.gif
else
echo "No .mov files found in the directory."
fi
英文:
I'm writing a Raycast bash script that converts the most recent Screen Recording into a Gif using this tool. The script is below. The line: ffmpeg -i "$recent_file" -pix_fmt rgb24 -r 10 -f gif - | gifsicle --optimize=3 --delay=3 > out.gif
works properly when run in Terminal. Unfortunately, it doesn't output out.mov
when run in Raycast, despite the fullOutput
of Raycast showing it completes as intended (see screenshot). Is there some kind of setting required in Raycast to allow the use of these command-line tools?
#!/bin/bash
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Gif Most Recent Screen Recording
# @raycast.mode fullOutput
# Optional parameters:
# @raycast.icon 🤖
# Documentation:
# @raycast.author willbeing
# @raycast.authorURL https://raycast.com/willbeing
directory="/Users/willbeing/Desktop/Screenshots" # Replace with your desired directory
# Check if the directory exists
if [ ! -d "$directory" ]; then
echo "Directory does not exist."
exit 1
fi
# Check if the directory exists
if [ ! -d "$directory" ]; then
echo "Directory does not exist."
exit 1
fi
# Retrieve the most recent .mov file
recent_file=$(ls -t "$directory"/*.mov 2>/dev/null | head -n 1)
# Output the most recent .mov file
if [ -n "$recent_file" ]; then
ffmpeg -i "$recent_file" -pix_fmt rgb24 -r 10 -f gif - | gifsicle --optimize=3 --delay=3 > out.gif
else
echo "No .mov files found in the directory."
fi
答案1
得分: 1
脚本按预期工作。感谢 @CharlesDuffy,我了解到了一些有价值的调试工具...
- 启用 Retrace:
PS4=':$LINENO+'; set -x
- 将 stderr 重定向到已知位置:
exec 2>/tmp/myscript.$$.log
- 比较两个环境之间的环境变量:您可以使用
declare -p
来转储几乎所有内容,或者使用env
仅查看环境变量。
...当然还要检查一些显而易见的事情,比如检查输出文件的目录。在 raycast 的情况下,它是 scripts
目录(我没有查看的地方) 🧘♂️
英文:
Script worked as intended. Thanks to @CharlesDuffy I learned about some valuable debugging tools...
- Enable Retrace:
PS4=':$LINENO+'; set -x
- Redirect stderr to a known location:
exec 2>/tmp/myscript.$$.log
- Compare environment variables between the two environments: you can use
declare -p
to dump pretty much everything orenv
for just environment.
...and of course to review the obvious, such as check the directory of the output file. In the raycast case it was the scripts
directory (where I was not looking) 🤦♂️
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论