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).
我正在尝试使用MonoMac创建一个简单的应用程序,并且需要执行apple脚本来访问来自不同媒体播放器的播放列表信息(请参阅我之前的问题)。
I decided to give MonoMac a try because I am very familiar with C# and .net development and there is a nice Websocket implementation.
我决定尝试MonoMac,因为我非常熟悉C#和.net开发,并且有一个很好的Websocket实现。
Unfortunately there seems to be no working wrapper for NSAppleScript. I tried Frederic Forjans implementation and tried to use monobjc.
不幸的是,似乎没有NSAppleScript的工作包装器。我尝试了Frederic Forjans的实现,并试图使用monobjc。
Frederics wrapper class does not even compile when I use his code I get the following exception:
当我使用他的代码时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'
when creating a new NSString
instance. However new NSDictionary();
which is located in the same assembly works fine.
在创建新的NSString实例时。然而新的NSDictionary();位于同一装配中的工作正常。
When using monobjc I get the following error:
使用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
Can anyone suggest a simple and working way to execute apple scripts in a mono environment?
任何人都可以建议一个简单而有效的方法在单声道环境中执行苹果脚本吗?
3 个解决方案
#1
4
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.
如果不使用Monobjc运行时二进制文件运行它们,则无法直接使用Monobjc程序集。无论您是要构建基于Cocoa还是控制台的应用程序,都可以在Monobjc的网站上找到相关教程,以帮助您入门。
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.
实现应用程序间通信的最简单方法是使用ScriptingBridge框架。许多应用程序提供脚本定义,然后可以以面向对象的方式使用:请查看本指南以获取更多详细信息。
Note that the scripting bridge will only works with scripting enabled applications (like iTunes, iCal, iMovie, Finder, etc).
请注意,脚本桥仅适用于启用脚本的应用程序(如iTunes,iCal,iMovie,Finder等)。
Monobjc supports the ScriptingBridge framework; there are even two sample applications (SBSetFinderComment and ScriptingBridgeiCal) that show how to integrate it.
Monobjc支持ScriptingBridge框架;甚至有两个示例应用程序(SBSetFinderComment和ScriptingBridgeiCal)展示了如何集成它。
#2
1
If possible try using Monobjc. Monobjc provides a very straightforward way of executing custom AppleScript.
如果可能的话尝试使用Monobjc。 Monobjc提供了一种执行自定义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.
我写了一篇博文,解释了相同的内容。还提供了一个Monobjc项目示例。
#3
0
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.
我试图从WinForms Mono项目中执行AppleScript,最终构建了我自己的AppleScript Slim小AppleScript执行库。 !00%的代码来自Mono Develop项目。
AppleScript Slim: https://applescriptslim.codeplex.com/
AppleScript Slim:https://applescriptslim.codeplex.com/
#1
4
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.
如果不使用Monobjc运行时二进制文件运行它们,则无法直接使用Monobjc程序集。无论您是要构建基于Cocoa还是控制台的应用程序,都可以在Monobjc的网站上找到相关教程,以帮助您入门。
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.
实现应用程序间通信的最简单方法是使用ScriptingBridge框架。许多应用程序提供脚本定义,然后可以以面向对象的方式使用:请查看本指南以获取更多详细信息。
Note that the scripting bridge will only works with scripting enabled applications (like iTunes, iCal, iMovie, Finder, etc).
请注意,脚本桥仅适用于启用脚本的应用程序(如iTunes,iCal,iMovie,Finder等)。
Monobjc supports the ScriptingBridge framework; there are even two sample applications (SBSetFinderComment and ScriptingBridgeiCal) that show how to integrate it.
Monobjc支持ScriptingBridge框架;甚至有两个示例应用程序(SBSetFinderComment和ScriptingBridgeiCal)展示了如何集成它。
#2
1
If possible try using Monobjc. Monobjc provides a very straightforward way of executing custom AppleScript.
如果可能的话尝试使用Monobjc。 Monobjc提供了一种执行自定义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.
我写了一篇博文,解释了相同的内容。还提供了一个Monobjc项目示例。
#3
0
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.
我试图从WinForms Mono项目中执行AppleScript,最终构建了我自己的AppleScript Slim小AppleScript执行库。 !00%的代码来自Mono Develop项目。
AppleScript Slim: https://applescriptslim.codeplex.com/
AppleScript Slim:https://applescriptslim.codeplex.com/