在终端中运行自定义 Bash 脚本可以正常工作,但在 RayCast 中却不行。

huangapple go评论66阅读模式
英文:

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

在终端中运行自定义 Bash 脚本可以正常工作,但在 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

# 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

在终端中运行自定义 Bash 脚本可以正常工作,但在 RayCast 中却不行。

答案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 or env 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) 🤦‍♂️

huangapple
  • 本文由 发表于 2023年6月12日 00:10:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76451345.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定