Apple Script中的调用函数

我一直在使用Apple Script作为Finder扩展程序FinderGo的工具。 由于沙箱,所有脚本都必须位于“ Application Scripts文件夹中。

今天,我正在重写我的Xcode扩展名XcodeWay。 在Xcode 8之前,我们可以使用Xcode插件和各种魔术使梦想成真在myway133 / XcodeWay:XcodeWay / Helper / FTGEnvironmentManager.m @ 1.0 #L50上。 但是自从引入Xcode Source Editor Extension以来,它不起作用。 所以我将XcodeWay重写为myway133 / XcodeWay @ 1.1.0 (发行版)的扩展

扩展程序必须在沙箱中运行。 如果将XcodeWayExtensions.entitlements App Sandbox切换为NO ,则不会加载。 因此,沙箱在很多方面限制了我想要做的事情。 在Xcode 9下,我无法使用NSWorkspace打开Finder

因此,我想我也可以使用Apple Script ,它的工作原理很吸引人。 唯一的限制是代码重用,因为我只知道如何运行整个脚本。 一种方法是导入其他Apple脚本stackoverflow.com/questions/2606136/import-applescript-methods-in-another-applescript,但我想我将在1个脚本中编写所有函数,并找出如何调用特定函数。

按功能,我也指处理程序,过程。 多亏了开源,我遇到了这段脚本编写器,这几乎启发了我。

所以这是我的脚本,其中包含许多功能。 这是ScriptRunner,解释了如何构建NSAppleEventDescriptor 。 请注意,您需要import Carbon

 导入Carbonfunc eventDescriptior(functionName:String)-> NSAppleEventDescriptor { 
var psn = ProcessSerialNumber(highLongOfPSN:0,lowLongOfPSN:UInt32(kCurrentProcess))
让target = NSAppleEventDescriptor(
descriptorType:typeProcessSerialNumber,
字节:&psn,
长度:MemoryLayout .size
)let event = NSAppleEventDescriptor(
eventClass:UInt32(kASAppleScriptSuite),
eventID:UInt32(kASSubroutineEvent),
targetDescriptor:目标,
returnID:Int16(kAutoGenerateReturnID),
transactionID:Int32(kAnyTransactionID)
)let function = NSAppleEventDescriptor(string:functionName)
event.setParam(function,forKeyword:AEKeyword(keyASSubroutineName))返回事件
}

原始故事https://github.com/onmyway133/blog/issues/88