你如何将AppleScript脚本置于版本控制之下?

cha*_*lax 26 git applescript

我想知道这是否是最好的解决方案:

  • .applescript文件放在版本控制之下
  • 创建安装脚本以使用编译文件 osacompile

但也有.scptd目录.或者我可以将两个.applescript.scpt文件置于版本控制之下?

什么是最好的解决方案?

Bru*_*sky 26

我喜欢@ DanielTrebbien的解决方案,但是我希望人们为了使用我的github项目而实现它有点太复杂了.一个更简单的选项,只是让你看到差异中的文本更改是告诉diff进程使用osadecompile textconv.

添加到.gitattributes

*.scpt diff=scpt
Run Code Online (Sandbox Code Playgroud)

添加到.git/config

[diff "scpt"]
  textconv = osadecompile
  binary=true
Run Code Online (Sandbox Code Playgroud)

这是来自AppleScript-droplet github项目的示例差异

$ 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文件.

  • 我感觉这种方法可以避免 scpt 文件在 github 中不可见的问题,但我担心克隆存储库的其他人也需要添加它。 (2认同)

dj *_*zie 6

我总是将.applescript(纯文本文件)放在版本控制(SVN)中.通过这种方式,我可以轻松地在不同版本之间进行比较,对于多用户来说也很容易.您可以突出显示其他用户所做的更改.对于二进制文件,例如编译的脚本文件,这是不可能的.