A third way of putting AppleScript into git

git
(Doeke Zanstra) #1

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)

1 Like

(CK) #2

How is it not as seamless as the first way ?

0 Likes

(Doeke Zanstra) #3

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?

0 Likes

(CK) #4

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

0 Likes

(Doeke Zanstra) #5

:cry: :pensive: :slightly_frowning_face:

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

0 Likes

#6

Fenced Markdown (for syntax highlighting) ?

0 Likes

(Thomas Tempelmann) #7

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

0 Likes

(Doeke Zanstra) #8

Good to hear :slight_smile:.

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

0 Likes

(Doeke Zanstra) #9

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).

0 Likes