简体   繁体   English

使用Mono设置桌面墙纸

[英]Set the desktop wallpaper using Mono

I have C# code in .NET 3.5 that sets the desktop background in Windows Vista/7. 我在.NET 3.5中有C#代码,可在Windows Vista / 7中设置桌面背景。 I would like to change my code to be cross-platform Windows/Mac/Linux by tweaking it so that it can run through Mono. 我想通过调整代码将其更改为跨平台的Windows / Mac / Linux,使其可以在Mono中运行。 The only Interop call in my code is the one to set the wallpaper. 我的代码中唯一的Interop调用是设置墙纸的调用。

I understand that each platform will require a different method/script for this to work; 我了解每个平台都需要使用不同的方法/脚本才能运行; my plan is to check OS & version and run the appropriate code as needed. 我的计划是检查操作系统和版本并根据需要运行适当的代码。 So far I've found the following non-mono resources which may help: 到目前为止,我发现了以下非单一资源可能会有所帮助:

Several of these have answers which appear to include scripts which maybe could be executed using a call to the shell/command line in each environment through code? 其中几个答案似乎包含脚本,可以通过在每个环境中通过代码调用shell /命令行来执行这些脚本?

How can I change the desktop background using mono in Linux and Mac environments? 如何在Linux和Mac环境中使用Mono更改桌面背景?

Setting the Wallpaper on a Mac with Mono 在具有Mono的Mac上设置墙纸
I've put together a library called AppleScript Slim which is a C# dll that allows you to execute AppleScript from a WinForms (or really any) Mono application. 我整理了一个名为AppleScript Slim的库,它是一个C#dll,可让您从WinForms(或实际上任何一个)Mono应用程序执行AppleScript。 100% of the code for this project came straight from the Mono Develop source code, I just trimmed and repackaged the pieces I needed. 该项目的代码100%直接来自Mono Develop源代码,我刚刚裁剪并重新打包了所需的部分。

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

Here is the sample code on how to set the wallpaper using AppleScript I developed (and which works great): 这是有关如何使用我开发的AppleScript设置墙纸的示例代码(效果很好):

string applScript =
@"set theUnixPath to POSIX file ""{0}"" as text 
tell application ""Finder"" 
set desktop picture to {{theUnixPath}} as alias 
end tell";

MonoDevelop.MacInterop.AppleScript.Run(string.Format(applScript, localPath));

Setting the Wallpaper on Ubuntu with Mono (Work in Progress, I plan to use portions of the GCONF library for Mono as discussed in the question comments, haven't had the chance to try it yet) 在Ubuntu上使用Mono设置墙纸 (正在进行中,我计划将GCONF库的一部分用于Mono,如问题注释中所述,还没有机会尝试)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM