aweinstock314 / rust-clipboard

System Clipboard interfacing library in Rust
Apache License 2.0
361 stars 72 forks source link

NSPasteboard#generalPasteboard returned null when called from macOS launchd Launch Daemon #79

Open windy1 opened 3 years ago

windy1 commented 3 years ago

Hi, so I'm not entirely sure if this is an issue with the library; I suspect it's more of a side-effect, but when acquiring a ClipboardContext on macOS from a launchd process like

let mut clipboard: ClipboardContext = ClipboardProvider::new().unwrap();

my program panics with the error NSPasteboard#generalPasteboard returned null. The program works OK when I execute it directly.

I am using the following daemon descriptor:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>myprogram</string>
    <key>EnvironmentVariables</key>
    <dict>
        <key>RUST_LOG</key>
        <string>debug</string>
        <key>RUST_BACKTRACE</key>
        <string>1</string>
    </dict>
    <key>ProgramArguments</key>
    <array>
        <string>$HOME/.cargo/bin/myprogram</string>
    </array>
    <key>UserName</key>
    <string>$USER</string>
    <key>StandardOutPath</key>
    <string>$HOME/.myprogram/myprogram.log</string>
    <key>StandardErrorPath</key>
    <string>$HOME/.myprogram/myprogram.log</string>
    <key>KeepAlive</key>
    <true/>
</dict>
</plist>

Apologies if this isn't strictly related to this library. Any insight would be greatly appreciated!

qkdreyer commented 2 years ago

you should use launchctl asuser USER_ID where USER_ID can be id -u (i.e. 501 for default user)