问题标签 [nsappleeventdescriptor]

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 投票
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 投票
3 回答
1404 浏览

objective-c - 以编程方式将文本输入任何应用程序

是否有一个概念验证的 Objective-C 可执行文件,它使用 Apple 事件而不是 AppleScript 将一些文本输入到应用程序中,然后单击鼠标?

例如 AppleScript 等价于

它应该可以在 Mac OS X 10.9 上运行,最好是面向未来的(向后兼容性无关紧要)。上下文是我将从另一种语言调用 Objective-C 代码。

我这么说是因为我读到了:

从 Mac OS X 10.7 开始,低级 Cocoa API (NSAppleEventDescriptor) 仍然缺乏必要的功能(例如发送 Apple 事件的能力),而高级 Cocoa API(脚本桥)缺陷太大且受限于不可行appscript 样式包装器的基础。

和:

NSAppleScript 只能在主线程上安全使用

所以,我的目标是:

  1. 任何应用程序(按名称或当前)
  2. 任何键盘输入或鼠标
  3. 来自 C 或 Objective-C
  4. 几百毫秒内

谢谢!

0 投票
2 回答
984 浏览

objective-c - 无法在 SWIFT 中解开 NSAppleEventDescriptor

我有一个Applescript,它给了我一个结果。但我无法将值解开为字符串,因此我可以使用它。

NSLog 看起来像这样:

实际结果是一个字符串“test.swift”。我怎样才能解开/解析这个结果?

我试着添加这个:

我也尝试使用该方法descriptorForKeyword(<#keyword: AEKeyword#>),但我不知道设置 AEKeyword 的热度。

0 投票
4 回答
645 浏览

swift - 如何将日期信息传递给 AppleScript?

我正在制作一个可以通过 NSAppleScript 运行 AppleScript 的应用程序。一切都很好,但我无法弄清楚如何将日期信息从我的应用程序传递到 AppleScript。(由于 AppleScript 有日期类型,我想这是可能的)我将参数传递给 AppleScript 的方式是通过 NSAppleEventDescriptor。我从谷歌了解到我可以将它作为 typeLongDateTime 类型传递:

不幸的是,LongDateTime 类型早已不复存在,因为我使用的是 Swift 并且在 OS X 10.10 下。甚至核心服务功能 UCConvertCFAbsoluteTimeToLongDateTime 也已从 10.10.3 中删除。

现在我被困住了。

你有什么启发灵感的想法吗?

0 投票
1 回答
158 浏览

objective-c - NSAppleEventDescriptor 从脚本桥展开问题返回

我正在开发 OSX,Xcode 8.2。目标-C。我使用脚本桥来处理 Adob​​e InDesign。我有一个很长的 AppleScript,我想用 Scripting-Bridge 将其转换为 Objective-C,以利用其后台任务的可能性。

为了更好地理解,让我向您展示之前 applescript 的部分:

苹果脚本中的结果:

如果我想在我执行的applescript中获取字符串(注意“as string”):

在objective-c中翻译的方法:

结果显示:

看起来每个 Adob​​eInDesignCC2017TextCtxt 对象都包含两个 appleeventdescriptor 来标记单词的位置和长度。我需要访问它们以提取信息。我检查了h。文件,但找不到像在 applescript 中一样使用“作为字符串”提取文本的方法。如何访问描述符?任何想法表示赞赏。

0 投票
0 回答
574 浏览

swift - 将数据发送到另一个应用程序并从中获取响应

我正在尝试相互交流应用程序。

我在我的第一个应用程序中处理 Apple 事件

在第二个应用程序中,我正在创建NSAppleEventDescriptor对象

现在NSWorkspace我正在启动我的第一个应用程序

一切都很好,调用了函数handleGetURLEvent,但是......我replyEvent.desciptorType也不kAENullEvent知道如何replyEvent进入我的第二个应用程序。

我想这个解决方案有问题。

所以我的问题是我怎样才能简单地将数据发送到我的其他应用程序并取回一些数据?

0 投票
1 回答
121 浏览

macos - 在 macOS 上使用预填充字段以编程方式打开消息

我正在尝试使 QR 码在 macOS 上可操作。我发现我可以通过使用 imessage 作为 URI 或 sms 作为 URI 打开 Messages 应用程序:

但是我无法添加任何参数,因此我可以预先填充文本的正文。如何预填充身体?

短信 URI 仅在 10.14 Mojave 之后才出现。

PS:iMessage URI 用逗号分隔电子邮件将进行群聊。

处理 URL (_handleGURL..) 的 Messages.app 方法获取此 NSAppleEventDescriptor:

在此处输入图像描述

0 投票
1 回答
29 浏览

objective-c - 从 final cut pro x 中解析 bmrk NSAppleEventDescriptor

在 Final cut pro 中,我分享到我的应用程序。

使用以下代码

我得到了这样的东西。
'aevt''odoc'{ '----':[ 'bmrk'(1012/$626F6F6BF403000000000410300000000000000000000000000000000000000000000000000000000000000000000000C00200000400000003030000000200000500000001010000557365727300000009000000010100006D75796F756E676B6F0000000900000001010000446F63756D656E747300000007000000010100006161612E6D7866001000000001060000100000002000000034000000480000000800000004030000BC300600000000000800000...

我期望像 /Users/hansome/Document/a.mov 这样的可读信息

我该如何解析这个?