运行 启动时的 c# 程序

Running c# programs on startup

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

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

我的程序 运行 正常运行,所以我想使用 Mac 自动程序自动启动。 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();
    }

我不知道如何使用 Automator 实现此目的,但您要求另一种方法:

我制作了一个名为 RepoZ I wanted to start with macOS, too. This works by throwing a launch agent file 的工具来 /Library/LaunchAgents/

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

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