从Cocoa应用程序运行AppleScript [英] Run AppleScript from Cocoa Application

查看:552
本文介绍了从Cocoa应用程序运行AppleScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能运行一个AppleScript code的Cocoa应用程序里面?

Is it possible to run an AppleScript code inside an Cocoa Application?

我试过NSAppleScript类,但没有成功。

I've tried NSAppleScript class, but no success.

此外,没有苹果允许这样做?

Also, does Apple allow this?

推荐答案

您提到的X code的不保存脚本您的应用程序的资源路径。那是对的。你必须告诉X code至做到这一点。首先编译脚本添加到您的项目。然后打开你的目标,找到了复制包资源的动作。从文件列表成操作拖动你的脚本。这样你的脚本复制到自动应用的资源,使您不必手动来做。

You mentioned xcode wasn't saving the script to your app's resources path. That is correct. You have to tell xcode to do this. First add the compiled script to your project. Then open your target and find the "Copy Bundle Resources" action. Drag your script from the files list into that action. This way your script is copied to your app's resources automatically so you don't have to do it by hand.

每当我在可可应用程序中使用已编译的AppleScript I,1)添加脚本到项目,2)创建一个新类来控制的AppleScript,3)使用以下init方法的类,以及4)阻力脚本到目标的复制包资源的行动。

Whenever I use a compiled applescript in a cocoa application I, 1) add the script to the project, 2) create a new class to control the applescript, 3) use the below init method for the class, and 4) drag the script to the "Copy Bundle Resources" action of the target.

-(id)init {
    NSURL* scriptURL = [[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:@"applescripts" ofType:@"scpt"]];
    if ([self initWithURLToCompiledScript:scriptURL] != nil) { //attempt to load the script file
    }
    [scriptURL release];
    return self;
}

这篇关于从Cocoa应用程序运行AppleScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆