A third way of putting AppleScript into git

There are currently two ways of putting AppleScript into git. First is just by adding the binary .scpt-files. You don’t get much benefit from using git, but it works.

The second way is to save your AppleScript source as text-files, and put these into git. You get advantages from git, but it is not as seamless as the first way.

Introducing osagitfilter

Now you can combine those two ways by using the osagitfilter utility. Technically, it’s a git filter that translates AppleScript’s binary format into the text-representation which then will be used by git’s internal workings.

See the repository’s readme for installation instructions. After that, you can put compiled script files, AppleScript applications and script bundles in git as if they where regular text-files. When you then clone this repository, the files are re-assembled bit-perfect.

Let me demonstrate this by an example. First create a git-repository:

git init osagitfilter-demo
cd osagitfilter-demo

Now create the AppleScript-file my_script.scpt in this folder with the following contents:

display dialog "What's your name" default answer ""
say "Hi there, " & text returned of result

Since we don’t want to add a binary file to git, we first need to associate the .scpt-extension with the osagitfilter (you need to explicitly opt-in every repository). This can be done by adding a line to the .gitattributes-file, connecting the .scpt-extension to the osa filter:

echo "*.scpt filter=osa" >> .gitattributes

Now the files can be added to git:

git add .gitattributes my_script.scpt
git commit -m Initial

Now let’s change the script by appending & ", I like your name" to the say command in the my-script.scpt file. Don’t forget to save.

Now when you run git diff, you can see the changes you made as you would with text-files. You don’t need to stick with the command-line: I can confirm it works with GitHub Desktop. It should also work with other GUI’s, but I haven’t tested this.

Not only AppleScript

The program is called osagitfilter, so you can also add JavaScript .scpt-files. There is also a feature that prevents you from accidently adding AppleScript-debugger files to git (a special file format used by the indispensible Script Debugger).

I hope osagitfilter will be useful tool. It will not completely replace the first two methods, but it’s nice to have an alternative to them.

(this article has also been posted to my blog)

3 Likes

How is it not as seamless as the first way ?

Multiple reasons. Some that come to mind when working with AppleScript-source as text files:

  • You need to hit the compile-button to initialise syntax highlighting
  • You probably need some kind of make/build script, especially when creating an application or script bundle. When working with .scpt-files, a build/make file would also come in handy, but you don’t need it for basic stuff.
  • Commands like path to resource works different in an script bundle.

Does this make any sense?

:no_mouth:­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­

:cry: :pensive: :slightly_frowning_face:

(and how do you make a post at least 20 characters with only one emoticon?)

Fenced Markdown (for syntax highlighting) ?

Most awesome! I do have .scpt files in many of my git projects, and this is quite useful to me.

Good to hear :slight_smile:.

Please let me know how it’s working out for you.

I not sure what you mean with Fenced MarkDown. However, with osagitfilter there is no need to user markdown. See for exampe this AppleScript file on GitHub.

When you clone the repository, while having osagitfilter installed, the super_script.scpt file is stored as a compiled AppleScript file on your disk, while having “kinda” syntax highlighting on GitHub (and also in your git diff tool).

Are these AppleScript-debugger files the ones that are no longer supported in Script Debugger 8 (and that I have never used and don’t care about)?

And does this filter otherwise work fine with scripts and script applets created, opened and modified by Script Debugger (I use Script Debugger for all my AppleScript stuff). Will it work with Script Debugger’s enhanced applets?

Thanks for any help as I’d love to add my AppleScript projects to git and this sounds like a great solution.

You are correct, I was referring to the AppleScript Debugger files, up to including version 7. Starting at version 8, you don’t need to worry about this anymore.

And osagitfilter will work with all script applets, including the enhanced ones. However, I’m not sure this is your best option. When you save a script as an application, this also includes the plumbing needed for an application. osagitfilter won’t touch this plumbing, but it will end up in git.

osagitfilter works best with plain Compiled Script format (file extention .scpt).

1 Like