Managing Applescript with git version control

I manage my applescript in github. When we moved to github, we switched all our scripts to .applescript plain text files for git compatibility. We deploy via script, and the deployment scripts parse metadata from the scripts themselves to see the filetype to deploy as (ie, run-only, .scptd, .app, etc) and figure out where they’re deploying to based on the GIT branch, read from the .git/HEAD file.

This works, but there are serious issues. Anything that must contain resources, so deployed as a .app or a .scptd bundle, we’re having the deployment code save over the .scpt file inside the bundle at:
[bundle name].scptd/Contents/Resources/Scripts/main.scpt
But this prevents us from managing the bundled resources on git.
Additionally, for our .apps, I think updating the .scpt inside breaks code signing.
Also, bundle and export settings for Script Debugger aren’t saved with the .applescript file, although we could store those values in the script metadata, parse them out, and set the values via script on export.
Libraries with dictionaries also don’t play nicely with this. The .applescript copy in our git folder won’t compile, because it’s disassociated from the dictionary inside the .scptd.
All in all, it’s a less than ideal solution.

I was excited when I heard that Script Debugger added a feature intended for helping with Version Control. In Preferences → Building, there’s now the checkbox for:

Saving Script Bundles
Save .scptd files in version-control-friendly format
Checking this option causes .scptd files to be saved with their source internally in both .rtf and .scpt format. When opening, the .rtf format is always preferred.

This sounds great - I can use .scptd bundles, AND use git.

But in git, .rtf’s aren’t rendered. Researching this, I found this thread:
[I tried linking, but is says I can’t put links in posts, so I butchered it] forum.latenightsw [com] /t/applescript-support-and-vcs-support/520/40

Which seems to confirm the issue.

Am I missing something? It doesn’t seem practical to merge .rtf’s in git, making this feature not-useful.

Is there a git extension to render rtf’s, instead of displaying the raw markup? A 3rd party merge tool people are using that supports .rtf?

Or from another angle - if the purpose of this feature is Version Control compatibility, why is Script Debugger using a .rtf, if .rtf is not standardly (usefully) compatible with Version Control? If this is the intended use, why not a .applescript text copy of the source inside the bundle, that Script Debugger prioritizes when opening?

I feel like I’m missing something, given that the preferences pane specifies this feature as being specifically for GIT compatibility.

Thanks,

Tom.

1 Like

I may have found my answer. I looked into github extensions first and found nothing. But now I started looking into third party merge tools; it appears at least Kaleidoscope, Araxis Merge, and Beyond Compare all support .rtf files, so I it looks like I can just go with the .rtf and buy an external merge tool.

Still curious if there’s a reason not to just save the copy of the source inside the bundle as .applescript plaintext though.

In a word, compatibility. Script Debugger can save what it likes in a .scptd bundle, but if that code gets ignored or even lost when opened in another editor, people aren’t going to be happy. Using .rtf lets Script Debugger take advantage of the autosave format and retain full file compatibility.

The only other option would be a custom file format (in effect, by modifying how a .scptd file is handled, or directly). It’s something we’ve discussed several times, but the cons always outweigh the pros.

Thanks Shane. So I reached the right conclusion here - that the intention of the feature is that people would be using an external merge tool that supports rendering rtf to merge?

Pretty much. It was a case of something being better than nothing.

A step by step guide would be great!
Title proposal: Use github to gain version control over my applescripts

Thanks in advance!

Apple’s FileMerge also supports .rtf files.

1 Like

Another solution is to use osagitfilter (disclaimer, I wrote this).

The major downside of this tool is, everyone accessing the repository needs to have this tool installed. It works pretty well, but it’s not for everyone. Maybe you can give it a try.

1 Like

Thanks. I had missed your comment in this thread prior… then I just came back to do another forum post, and first found your thread announcing asagitfilter, then found you’d replied here, and I missed it. I’ll take a look!

@tspoon, did you arrive at a good solution? I’d love to know where you landed as I’m really keen to get my AppleScript projects into git. Your initial workflow sounds like way more work than I’d be willing to invest in.

If I just put the AppleScript binaries into git, I understand that I won’t be able to use the diff or merge features of git, but will I still be able to discard changes made since my last commit and revert to an earlier commit (e.g. based on reading my commit messages)?

Are there any other issues to be aware of with putting Script Debugger projects into git?

I have not yet tried osagitfilter.

If you can store your files as .applescript, just do that and you’re good to go. Everything should work fine, and there’s nothing else to be done.

But if you need to save as .scptd then I’d try osagitgilter first.

I did try Apple’s FileMerge as an merge tool; it works, but it’s way too feature-poor for any kind of serious merge. I’d need to use an external tool.

At the moment, every file saved as a .scptd, every time I change branches, Script Debugger sees the file as corrupt. I sent Shane several examples of these, he said he could see what the issue was, but it’s not yet resolved.

Does the same happen for scripts saved as a .scpt file (i.e. as a script rather than a script bundle)? I presume that applets will have the same behaviour as .scpt files as they store the scripts in main.scpt.

I don’t know. Anything without bundled resources, I’d save as an .applescript.

I can test that for you, but I’m actually about to be traveling, it may be a bit.

The .AppleScript format just seems a bit cumbersome, and most of my projects have resources and are saved as applets in .app format.

I should just test it out myself I suppose, I’m just a bit nervous but I guess I can just copy a test script first before trying an actual project. Thanks for offering to test it for me though.

If you get any further towards a better solution please update this thread with your findings. I’d love to hear about it.

FYI, it’s resolved here, and should be in the next beta.

1 Like

There’s one great thing about .applescript files, IMO. The code doesn’t devolve into raw (chevron) syntax if you open it on a machine with a missing application. Of course, you won’t be able to successfully compile the script, but you can still read all the commands that target the missing app.

Yes, I strongly prefer .AppleScript whenever possible. It’s just things requiring resources that just don’t get along nicely with that.

I’ll be back with any progress.

I haven’t ever lost any code in git. When Script Debugger thinks a .scptd is corrupt following changing branches, it always “recovers” the full script text 100% accurately.

1 Like

Fanstastic! Thanks.

I generally haven’t used the betas, but I’ll look out for the next one.

Can apps like FastScripts, Keyboard Maestro or the system-wide scripts menu execute scripts saved in .AppleScript format? I presume I’d have to copy and paste or export them into a different format to deploy them.

Is it just as easy to develop in Script Debugger in .AppleScript format?

FastScripts 3 definitely can. FastScripts is a great investment—it’s already awesome and keeps getting better!

1 Like