MonoMac - 我如何执行苹果脚本

发布于 2024-11-05 01:43:30 字数 1412 浏览 5 评论 0 原文

我正在尝试使用 MonoMac 创建一个简单的应用程序,并且需要执行苹果脚本来访问来自不同媒体播放器的播放列表信息(请参阅我的 上一个问题)。

我决定尝试一下 MonoMac,因为我非常熟悉 C# 和 .net 开发,并且有一个很好的 Websocket 实现。

不幸的是,NSAppleScript 似乎没有可用的包装器。我尝试了 Frederic Forjans 实现 并尝试使用 monobjc

当我使用 Frederics 的代码时,包装类甚至无法编译,出现以下异常:

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'MonoMac, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
File name: 'MonoMac, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'

创建新的 NSString 实例时。然而,位于同一程序集中的 new NSDictionary(); 可以正常工作。

使用 monobjc 时出现以下错误:

Unhandled Exception: System.TypeInitializationException: An exception was 
thrown by the type initializer for Monobjc.ObjectiveCRuntime ---> 
System.EntryPointNotFoundException: monobjc_install_bridge
  at (wrapper managed-to-native) Monobjc.NativeMethods:InstallBridge ()
  at Monobjc.ObjectiveCRuntime..cctor () [0x00000] in :0 
  --- End of inner exception stack trace ---
  at CocoaApplication1.Program.Main () [0x00000] in :0 

谁能建议一种在单声道环境中执行苹果脚本的简单且有效的方法?

I am trying to create a simple app with MonoMac and need to execute apple script to access playlist information from different media players (see my previous question).

I decided to give MonoMac a try because I am very familiar with C# and .net development and there is a nice Websocket implementation.

Unfortunately there seems to be no working wrapper for NSAppleScript. I tried Frederic Forjans implementation and tried to use monobjc.

Frederics wrapper class does not even compile when I use his code I get the following exception:

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'MonoMac, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
File name: 'MonoMac, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'

when creating a new NSString instance. However new NSDictionary(); which is located in the same assembly works fine.

When using monobjc I get the following error:

Unhandled Exception: System.TypeInitializationException: An exception was 
thrown by the type initializer for Monobjc.ObjectiveCRuntime ---> 
System.EntryPointNotFoundException: monobjc_install_bridge
  at (wrapper managed-to-native) Monobjc.NativeMethods:InstallBridge ()
  at Monobjc.ObjectiveCRuntime..cctor () [0x00000] in :0 
  --- End of inner exception stack trace ---
  at CocoaApplication1.Program.Main () [0x00000] in :0 

Can anyone suggest a simple and working way to execute apple scripts in a mono environment?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

萌能量女王 2024-11-12 01:43:30

如果不使用 Monobjc 运行时二进制文件运行 Monobjc 程序集,则无法直接使用它们。无论您想要构建基于 Cocoa 的应用程序还是控制台应用程序,都有相应的教程在 Monobjc 的网站上帮助您入门。

实现应用程序间通信的最简单方法是使用 ScriptingBridge 框架。许多应用程序提供了可以以面向对象的方式使用的脚本定义:查看本指南了解更多详细信息。

请注意,脚本桥仅适用于启用脚本的应用程序(例如 iTunes、iCal、iMovie、Finder 等)。

Monobjc 支持 ScriptingBridge 框架;甚至还有两个示例应用程序(SBSetFinderCommentScriptingBridgeiCal) 展示了如何集成它。

You cannot use the Monobjc assemblies directly without running them with the Monobjc runtime binary. Whether you want to build a Cocoa based or console application, there are tutorials for that on the Monobjc's website to help you getting started.

The easiest way to achieve inter-application communication is to use the ScriptingBridge framework. Many applications provide scripting definitions that can be then used in an object-oriented way: take a look at this guide for more details.

Note that the scripting bridge will only works with scripting enabled applications (like iTunes, iCal, iMovie, Finder, etc).

Monobjc supports the ScriptingBridge framework; there are even two sample applications (SBSetFinderComment and ScriptingBridgeiCal) that show how to integrate it.

一场春暖 2024-11-12 01:43:30

如果可能的话尝试使用 Monobjc。 Monobjc 提供了一种非常简单的执行自定义 AppleScript 的方法。

以下代码片段显示了主要步骤:

string script = ". . . . . . . . . ."; // some applescript text
NSDictionary error = null;
NSAppleScript scr = new NSAppleScript(script);
NSAppleEventDescriptor result = scr.ExecuteAndReturnError(out error);
string retval = result.StringValue;

我写了一篇 博客文章 对此进行了解释。还提供了一个示例 Monobjc 项目。

If possible try using Monobjc. Monobjc provides a very straightforward way of executing custom AppleScript.

The following code snippet shows the main steps:

string script = ". . . . . . . . . ."; // some applescript text
NSDictionary error = null;
NSAppleScript scr = new NSAppleScript(script);
NSAppleEventDescriptor result = scr.ExecuteAndReturnError(out error);
string retval = result.StringValue;

I have written a blog post explaining the same. There's also a sample Monobjc project provided.

昵称有卵用 2024-11-12 01:43:30

我试图从 WinForms Mono 项目执行 AppleScript,最终构建了我自己的小型 AppleScript 执行库,称为 AppleScript Slim。 !00% 的代码来自 Mono Develop 项目。

AppleScript Slim:https://applescriptslim.codeplex.com/

I was trying to execute AppleScript from a WinForms Mono project and ended up building my own little AppleScript execution library called AppleScript Slim. !00% of the code came from the Mono Develop project.

AppleScript Slim: https://applescriptslim.codeplex.com/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文