问题标签 [nsapplescript]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
2706 浏览

objective-c - 当我将 OS X 升级到 10.9 时,我的 applescript 不再工作

以下代码试图打开代理设置对话框,

在我将 Mac OS 升级到 10.9 之前,它一直运行良好。苹果脚本的第二部分,

它不再起作用了。所以如果有人能告诉我原因,我将不胜感激。


编辑:这是我的 .entitlements 文件信息,

0 投票
2 回答
446 浏览

nsapplescript - NSApplescript 在“do shell script..”中使用空格转义路径

我无法使用 NSApplescript 转义包含空格的路径:

上面的代码仅在应用程序位于不包含空格的路径中时才能正常工作,但是当将其移动到名称中包含空格的文件夹或硬盘驱动器中时,NSAppleScript 会失败。有什么建议吗?谢谢

0 投票
1 回答
674 浏览

applescript - 使用 NSAppleScript 在 Objective C 中创建和调用 AppleScript 应用程序使用相同的代码有不同的结果?

首先,我使用以下代码创建了一个 AppleScript 应用程序(文件名:UnloadTest.scpt):

并使用 NSAppleScript 类调用它,代码如下:

它可以正常工作,但它有一个问题:如果我想在另一台计算机上运行我的应用程序,我需要将“UnloadTest.scpt”文件中的用户名和我的密码更改为其他人的,这很愚蠢!所以我想换一种方式:使用“- (id)initWithSource:(NSString *)source”函数从代码创建一个AppleScript,我可以从我的APP界面发送用户名和密码:

但它对我来说失败了,看起来像

不成功。我认为这是AppleScript没有获得特权,但我不知道如何纠正它。

有没有人可以帮助我理解这个问题?

0 投票
1 回答
833 浏览

macos - 使用 NSAppleScript 执行的 AppleScript 不起作用

我在下面的主标题中调用并执行苹果脚本

但不起作用,而脚本

在 AppleScript 编辑器中运行良好。

欢迎您的评论

0 投票
1 回答
155 浏览

c++ - When launching an application using applescript, I am not getting the splash screen

When launching an application using applescript, I am not getting the splash screen

I am trying to launch an application and open a file using applescript. I am using this script in my c++ project. The application launcher code goes some what like this:

I am sorry that, i don't remember the exact command right now. I am using NSAppleScript to run the script in my project. The application is launched corretly. But splash screen in missing. (Application that I am trying to launch is adobe illustrator.

I had also tried the system command. system("open \"<application_path>\" --args \"<file_path>\"").

By this way, I was able to get the splash screen working, But, if the application was already running, it won't attempt to open the file. There might be some error in the code that I posted.

0 投票
2 回答
529 浏览

c++ - 如何使用可以作为 NSAppleScript 运行的 if else 条件生成 osascript

我正在尝试启动一个应用程序并通过 applescript 在其中打开一个文件。我可以通过 Apple Script Editor 做到这一点。这是我写的脚本:

如果应用程序在后台运行,单独启动无法将其带到前台(在脚本编辑器上方)。如果应用程序未运行,则激活无法显示启动画面。这就是为什么,我使用机器人启动和激活。

该脚本工作正常。但我需要我的 c++ 程序中的脚本。应用程序路径和文件路径将在运行时决定。所以我将脚本生成为 NSAppleScript 并执行脚本。生成的 NSApplescript 如下所示:

以上所有代码都在一行中,为了便于阅读,我将其打破。我收到一条错误消息variable e is not defined。这没有被执行。

我用来生成这个脚本的代码是:

我按照 user309603 的建议在 -e 之前添加了空格。现在我收到一个新错误:

错误“266:266:语法错误:预期行尾等,但发现脚本结尾。(-2741)”编号 1

0 投票
1 回答
2630 浏览

cocoa - -[NSAppleScript executeAndReturnError:] gives error with script that works in AppleScript Editor

I'm trying to find out if QuickTime player is paused or playing from Cocoa. I use the following small AppleScript in Script Debugger and AppleScript Editor and it returns true or false as expected:

However, the following code snippet in a Cocoa app isn't working:

After stepping through the above code my debug console looks like this:

debug console state

In case it's relevant, it takes about four seconds for the last debugger step, the one assigning a value to descriptor, to execute, which seems very long to me.

I built a simple command line tool app with just the above within the @autorelease block, and it works:

It's output (when QuickTime Player is running) is:

Stepping through the sandbox code in the debugger executes that descriptor assignment in less than a second. So what could be different in the app project that is preventing this from working?

0 投票
0 回答
192 浏览

objective-c - NSAppleScript 内存泄漏

我有 OS X 10.6 SDK 的代码。有一件事我无法理解。

[1]

在代码中,当 poolCount 为 100 时释放和分配 autoreleasepool。我发现总是存在泄漏。

但是下面的代码没有泄漏。

[2]

内部循环的自动释放池是 [1] 和 [2] 之间的区别。

请让我知道为什么在 [1] 的情况下内存泄漏。

0 投票
1 回答
660 浏览

macos - 应用程序如何在 Cocoa 中向自身发送(基本)Apple 事件?

我以为我在为应用程序委托中的“打开”菜单命令重写处理程序时非常巧妙:

在旧代码中,循环遍历每个文件 URL,我曾经直接调用我的窗口创建代码。然后我将实现单文件换成-application:openFile:它的多文件变体,并决定在-openDocument:.

我认为这很好。

单文件版本返回一个 BOOL 表示其成功。对于多文件版本,您应该调用应用程序对象的特殊函数。

我猜当你用一些文件启动你的应用程序时,Cocoa 的处理程序会使用打开文件 AppleEvent 来查看它们,调用-application:openFiles:,等待设置响应全局,然后发回 AppleEvent 回复。当我重用-application:openFiles:in 时-openDocument,我会在应用程序对象不期望它时发布到该全局......哦,废话。

哦,我可以提交文件进行处理,方法是把它们放在一个打开文件的 AppleEvent 中并发送给 self. 我环顾文档,发现除了我需要的所有内容:如何发送 AppleEvent 以及可能的 AppleEvent 列表及其参数。

有人可以在这里演示如何创建和发送打开文件 AppleEvent 吗?或者至少告诉我们事件 ID 和参数表在哪里?(关于脚本的各种 Cocoa 指南都参考了事件 ID 参考,但这是一个死链接,指向 Apple 的开发人员门户通用/搜索页面。)

0 投票
2 回答
161 浏览

cocoa - 使用applescript在最前面的应用程序中复制选择

我正在尝试使用以下代码将选定的文本复制到 Cocoa 应用程序中的剪贴板:

不幸的是,什么也没有发生。你知道可能是什么问题吗?