How would you put an AppleScript script under version control?

后端 未结 4 1540
深忆病人
深忆病人 2020-12-13 02:25

I was wondering if this was the best solution:

  • Put the .applescript files under version control
  • Create an installation script to compile the files wit
4条回答
  •  旧巷少年郎
    2020-12-13 02:52

    I keep the plain text .applescript files in Git, and I have a simple Bash script that I run every time I want to make a build of the app, which takes care of compiling the AppleScript. Here's my script:

    #!/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
    

    This script assumes that you have your entire app (i.e. the Contents/ folder and everything in it) inside the folder app/ in the root of your Git repository. It copies everything over to a new copy of the app in dist/, then compiles all AppleScript files in the Contents/Resources/Scripts/ folder of the new copy.

    To use this yourself, I recommend copying my script to bin/build.sh in the root of your repository, running chmod +x bin/build.sh to make it executable, and then just run ./bin/build.sh any time you want a new build of your app.

提交回复
热议问题