我想知道这是否是最好的解决方案:
osacompile但也有.scptd目录.或者我可以将两个.applescript和.scpt文件置于版本控制之下?
什么是最好的解决方案?
Bru*_*sky 26
我喜欢@ DanielTrebbien的解决方案,但是我希望人们为了使用我的github项目而实现它有点太复杂了.一个更简单的选项,只是让你看到差异中的文本更改是告诉diff进程使用osadecompile textconv.
*.scpt diff=scpt
Run Code Online (Sandbox Code Playgroud)
[diff "scpt"]
textconv = osadecompile
binary=true
Run Code Online (Sandbox Code Playgroud)
$ git diff
--- a/AppleScript-droplet.app/Contents/Resources/Scripts/main.scpt
+++ b/AppleScript-droplet.app/Contents/Resources/Scripts/main.scpt
@@ -1,3 +1,3 @@
-on open filelist
- ## Set useTerminal to true to run the script in a terminal
- set useTerminal to true
+on open file_list
+ ## Set use_terminal to true to run the script in a terminal
+ set use_terminal to true
Run Code Online (Sandbox Code Playgroud)
非常感谢@DanielTrebbien的回答让我看到了osadecompile.
Dan*_*ien 17
如果使用git,您可以使用过滤器驱动程序透明地(1)反编译SCPT文件,以便仅提交AppleScript源代码(称为"清理"二进制SCPT),以及(2)在签出时重新编译回SCPT(称为"涂抹"AppleScript源代码".
首先添加以下命名git-ascr-filter为的shell脚本/usr/local/bin:
#!/bin/sh
if [ $# -ne 2 ]; then
echo "Usage: $0 --clean/--smudge FILE">&2
exit 1
else
if [ "$1" = "--clean" ]; then
osadecompile "$2" | sed 's/[[:space:]]*$//'
elif [ "$1" = "--smudge" ]; then
TMPFILE=`mktemp -t tempXXXXXX`
if [ $? -ne 0 ]; then
echo "Error: \`mktemp' failed to create a temporary file.">&2
exit 3
fi
if ! mv "$TMPFILE" "$TMPFILE.scpt" ; then
echo "Error: Failed to create a temporary SCPT file.">&2
rm "$TMPFILE"
exit 4
fi
TMPFILE="$TMPFILE.scpt"
# Compile the AppleScript source on stdin.
if ! osacompile -l AppleScript -o "$TMPFILE" ; then
rm "$TMPFILE"
exit 5
fi
cat "$TMPFILE" && rm "$TMPFILE"
else
echo "Error: Unknown mode '$1'">&2
exit 2
fi
fi
Run Code Online (Sandbox Code Playgroud)
确保chmod a+x脚本.
运行以下命令配置'ascr'过滤器:
git config filter.ascr.clean "git-ascr-filter --clean %f" git config filter.ascr.smudge "git-ascr-filter --smudge %f"
然后添加到.gitattributes:
*.scpt filter=ascr
现在,每当您对SCPT文件进行更改git add时,反编译的AppleScript源将被暂存,而不是二进制SCPT.此外,每当您签出一个SCPT文件(实际上存储在存储库中的AppleScript blob)时,就会在磁盘上重新创建SCPT文件.