繁体   English   中英

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

[英]How would you put an AppleScript script under version control?

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

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

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

最好的解决方案是什么?

我喜欢@DanielTrebbien 的解决方案,但对我来说,期望人们实施以用于我的 github 项目有点太复杂了。 一个更简单的选项只是让您能够查看 diff 中的文本更改,即使用 osadecompile 将 diff 进程告知 textconv。

添加到 .gitattributes

*.scpt diff=scpt

添加到 .git/config

[diff "scpt"]
  textconv = osadecompile
  binary=true

这是来自我的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

非常感谢@DanielTrebbien 的回答,让我使用了 osadecompile。

编辑:现在是一个“官方”的 gitfilter 来做到这一点,称为osagitfilter 它建立在这个想法的基础上并修复了 osacompile 的一些怪癖......


如果使用 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

确保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 文件。

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

我将纯文本 .applescript 文件保存在 Git 中,并且我有一个简单的 Bash 脚本,每次我想要构建应用程序时都会运行该脚本,它负责编译 AppleScript。 这是我的脚本:

#!/usr/bin/env bash

APPNAME="My Awesome App"

# make sure we're in the right place
if [ ! -d ".git" ]; then
    echo "ERROR: This script must be run from the root of the repository."
    exit
fi

# clear out old build
rm -r dist/*
mkdir -p "dist/$APPNAME.app/"

# copy files
cp -r app/* "dist/$APPNAME.app/"

# compile all applescript
cd "dist/$APPNAME.app/Contents/Resources/Scripts/"
for f in *.applescript
do
    osacompile -o "`basename -s .applescript "$f"`.scpt" "$f"
    rm "$f"
done

此脚本假设您的整个应用程序(即Contents/文件夹及其中的所有内容)位于 Git 存储库根目录的文件夹app/中。 它将所有内容复制到dist/中的应用程序的新副本,然后编译新副本的Contents/Resources/Scripts/文件夹中的所有 AppleScript 文件。

要自己使用它,我建议将我的脚本复制到存储库根目录中的bin/build.sh ,运行chmod +x bin/build.sh使其可执行,然后随时运行./bin/build.sh你想要一个新版本的应用程序。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM