How to compile an AppleScript Script Library (scptd) with an Scripting Definition (sdef)

为君一笑 提交于 2020-01-05 10:05:08

问题


I want to be able to decompile and compile and AppleScript Script Library (scptd) with an Scripting Definition (sdef), so I can put the text source in version control.

The background of this question is to put my AppleScript sources in git. Most of my questions have been answered by this stackoverflow question/answer, but my question described here is still preventing me from putting all my scripts in git.

In this library test.scptd I have an handler with the name say it loud, and in the sdef file test.sdef it is declared as a command with the code SAYTLOUD.

When using osadecompile, I get an AppleScript text file test.applescript:

on say it loud whatToSay
  do shell script "say " & quoted form of whatToSay
end on say it loud

However, this source can't be compiled with osacompile, because the link to the sdef file has been broken and say it loud is not a valid identifier.

Luckily, I found the binary compile_as (source here), which is part of the excellent editor TextMate. When, decompiling, I get the following source file test_raw.applescript:

on «event SAYTLOUD» whatToSay
  do shell script "say " & quoted form of whatToSay
end «event SAYTLOUD»

This is what I want, because the code is still valid AppleScript and it's runnable. The only difference is you can't call the handler by name, but you need to use the raw code. No problems here.

My question: how do I compile the AppleScript file test_raw.applescript (with the raw codes), combined with the test.sdef file into an test.scptd.

An obvious answer would be to create my own decompile_as with Objective-C and OSAKit (if possible), but I do not posses the skills involved.


回答1:


The ideal solution is to put your .scptd bundles directly into your git repository, then set fire to the whole lot.

The second-best solution is to put your .scptd bundles directly into your git repository, then write your own 'diff' shell script that sits between your git client and your actual diff command (example). When the shim script receives files with .scptd suffixes, pass them to osadecompile and write the output to temp text files, then pass those file paths to your diff tool. That'll give you human-readable diffs without having to break AppleScript's (inherently scm-hostile) file formats. Won't help if you want to do merges as well, obviously, but that's between you and your elder gods.



来源:https://stackoverflow.com/questions/43386718/how-to-compile-an-applescript-script-library-scptd-with-an-scripting-definitio

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!