传递变量的AppleScript [英] Passing variables to an applescript

查看:124
本文介绍了传递变量的AppleScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在code运行我以x code AppleScript的是以下内容:

The code to run my applescript in xcode is the following:

NSString *path = [[NSBundle mainBundle] pathForResource:@"Script" ofType:@"scpt"];

    NSAppleScript *script = [[NSAppleScript alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:nil];

    [script executeAndReturnError:nil];

执行它之前,我想知道是否有可能将一些变量为它用。换句话说,我想从我的应用程序变量传递给一个AppleScript。

Before executing it, I was wondering if it was possible to set some variables up for it to use. In other words, i want to pass variables from my app to an applescript.

推荐答案

您可以使用的方法:

- (id)initWithSource:(NSString *)source

和使用 stringWithFormat 来建立你的AppleScript源和设置参数。

and use stringWithFormat to build your applescript source and setting the arguments.

NSString* scriptTemplate = ...;
NSString* actualScript = [NSString stringWithFormat:scriptTemplate, arg1, arg2, ... argN];
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:actualScript];

您也可以设计出更先进的替代机制,在那里你莫名其妙地标记你的Script.scpt参数,然后用替换它们stringByReplacingOccurrencesOfString:withString:

You could also devise a more advanced replacement mechanism, where you tag somehow your parameters in "Script.scpt" and then replace them using stringByReplacingOccurrencesOfString:withString:

这篇关于传递变量的AppleScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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