AppleScript的语法(多参数数量)内的Objective-C文件 [英] Applescript Syntax (Multiple Args) Inside Objective-C File

查看:951
本文介绍了AppleScript的语法(多参数数量)内的Objective-C文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图从Objective-C的,查询到终端运行一些shell命令中运行一个AppleScript。我遇到的问题与如何格式化的Objective-C中的命令,使脚本对象被正确引用。

I have been working on trying to run an Applescript from within Objective-C that queries out to the terminal to run some shell commands. I am running into an issue with how to format the command within Objective-C, so that the script object gets referenced properly.

这是剧本的样子,一个AppleScript

This is what the script looks like as an applescript

set thisFile to "Dev1.4"
set testTarget to "/Users/lab/Desktop/untitled"
do shell script     "/Users/lab/Desktop/TempRoot/myCommand.command " & thisFile & space & testTarget with administrator privileges

本脚本已经经过测试和验证在我来自一个AppleScript文件传递多个命令到终端命令文件前一个问题(<一个href=\"http://stackoverflow.com/questions/28833086/passing-multiple-parameters-from-applescript-to-terminal-command-script\">Passing从AppleScript的多个参数终端命令脚本)。

This script has been tested and verified in one of my prior questions about passing multiple commands from an applescript file to a terminal command file (Passing Multiple Parameters from Applescript to Terminal Command Script).

我的Objective-C的编码尝试如下:

My Objective-C coding attempt is below:

NSObject *arrayObj = arguments[0];

NSString *tmpString1 = [arguments objectAtIndex:0];
NSString *tmpString2 = [arguments objectAtIndex:1];

NSString * fullScript = [NSString stringWithFormat:@"'%@' & get quoted form of %@ & space & get quoted form of %@", scriptPath, tmpString1, tmpString2];

NSDictionary *errorInfo = [NSDictionary new];
NSString *script =  [NSString stringWithFormat:@"do shell script \"%@\" with administrator privileges", fullScript];

NSLog(script);

NSAppleScript *appleScript = [[NSAppleScript new] initWithSource:script];
NSAppleEventDescriptor * eventResult = [appleScript executeAndReturnError:&errorInfo];

如果有人能告诉我如何正确格式化该行创建了完整的脚本,这将大大AP preciated!

If anyone could tell me how to properly format this line that creates the full script, that would be greatly appreciated!

NSString * fullScript = [NSString stringWithFormat:@"'%@' & get quoted form of %@ & space & get quoted form of %@", scriptPath, tmpString1, tmpString2];

请让我知道如果您有任何疑问,或和,需要更多的信息。

Please let me know if you have any questions, and or, require more information.

编辑:

我发现在关于这个问题的一些新的信息。这似乎与@ShooTerKo的回答语法问题得到解决。然而正在发生的事情引起的AppleScript失败是文件路径不AppleScript的认可,因为AppleScript的不喜欢的空间,在它的文件路径名。

I have discovered some new Information in regards to the problem. It seems that with @ShooTerKo 's answer the syntax problem is resolved. However what is happening to cause the applescript to fail is that the file path is not recognized in Applescript because applescript doesn't like spaces in it's file path names.

例如:

set testTarget to "/Users/lab/Desktop/Problem Folder"
set thisFile to "Dev1.4"
do shell script "/Users/lab/Desktop/TempRoot/myCommand.command " & thisFile & space & testTarget with administrator privileges

将导致的AppleScript仅保存

will cause the applescript to only save

"/Users/lab/Desktop/Problem"

作为变量,因此无法获得正确的路径。这可以在我的调试模式中找到下面这个错误:

as the variable and therefore not get the correct path. This can be found in my debug mode with this error below:

Printing description of errorDescription->*errorDescription:
/bin/sh: /Users/lab/Library/Developer/Xcode/DerivedData/Branch_Copier_GUI-fqaphewyolyltbehjgtknknowmrr/Build/Products/Debug/Branch: No such file or directory

我会考虑重新命名我的项目包括下划线是通过AppleScript的更恰当PTED间$ P $,并做一些更多的研究,在这个新的错误。再次感谢大家的帮助,我真的AP preciate呢!

I will consider renaming my project to include underscores to be interpreted by applescript more appropriately and do some more research on this new error. Again thank you for the help, I really appreciate it!

推荐答案

是由的NSLog(fullScript)显示什么样的价值; ?我想你会得到一个

What value is shown by a NSLog(fullScript);? I think you'll get a

[...] get quoted form of Dev1.4 [...]

什么是无效的AppleScript语法。你也应该添加一个空格。顺便说一句,为什么要编写AppleScript的建筑物内的shell脚本?你只是不需要它在那里,所以请尽量只

what isn't a valid Applescript syntax. You should add another space also. BTW why do you want to write Applescript inside building a shell script? You just don't need it there, so please try just

NSString * fullScript = [NSString stringWithFormat:@"%@ '%@' '%@'", scriptPath, tmpString1, tmpString2];

希望它能帮助,迈克尔/汉堡

Hope it helps, Michael / Hamburg

这篇关于AppleScript的语法(多参数数量)内的Objective-C文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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