【问题标题】:Running c# programs on startup在启动时运行 c# 程序
【发布时间】:2021-01-26 04:48:33
【问题描述】:

如果我在终端中运行它,我刚刚制作了一个 c# 应用程序来组织我的桌面

/Library/Frameworks/Mono.framework/Versions/Current/Commands/mono Program.exe

我的程序正常运行,所以我想用 Mac automator 自动启动。 bash 命令亮起绿灯,但是当我打开应用程序时,它会打开然后立即停止。我做错了什么还是有不同的方式在启动时运行我的脚本。 这是我的 c# 代码的主要部分,如果有帮助,我可以将其全部粘贴在这里。

static void Main(string[] args)
    {
        FileSystemWatcher fileSystemWatcher = new FileSystemWatcher();
        fileSystemWatcher.Path = "/Users/user/Desktop/SortTheseFiles";
        fileSystemWatcher.Created += FileChanged;
        fileSystemWatcher.Changed += FileChanged;
        fileSystemWatcher.Renamed += FileChanged;
        fileSystemWatcher.EnableRaisingEvents = true;

        FileSystemWatcher fileSystemWatcherDownloads = new FileSystemWatcher();
        fileSystemWatcherDownloads.Path = "/Users/user/Downloads";
        fileSystemWatcherDownloads.Created += DownloadsChanged;
        fileSystemWatcherDownloads.Changed += DownloadsChanged;
        fileSystemWatcherDownloads.Renamed += DownloadsChanged;
        fileSystemWatcherDownloads.Deleted += DownloadsChanged;
        fileSystemWatcherDownloads.EnableRaisingEvents = true;

        Console.ReadKey();
    }

【问题讨论】:

    标签: c# bash macos automation


    【解决方案1】:

    我不知道如何使用 Automator 实现这一点,但您要求另一种方式:

    我制作了一个名为 RepoZ 的工具,我也想从 macOS 开始。这可以通过将a launch agent file 扔到/Library/LaunchAgents/ 来实现。

    【讨论】:

      【解决方案2】:

      通过一些额外的挖掘,我发现使用苹果脚本是可能的。这是我的代码

      tell application "Terminal"
          reopen
          activate
          do script "cd /Users/user/Desktop/CleanMyMac/CleanMyMac/bin/Release/netcoreapp3.1" in window 1
          do script "dotnet CleanMyMac.dll" in window 1
      end tell
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多