Skip to content

Instantly share code, notes, and snippets.

@qkdreyer
Last active Sep 1, 2021
Embed
What would you like to do?
NSPasteboard + launchd
make
make install
make start-without-launchd # nspasteboardlaunchd[33722:1132576] PasteboardName Apple CFPasteboard general PasteboardCount 263
make start-with-launchd # nspasteboardlaunchd[33732:1132768] PasteboardName (null) PasteboardCount 0
make uninstall
<?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>dev.qkdreyer.nspasteboardlaunchd</string>
<key>Program</key>
<string>/tmp/nspasteboardlaunchd</string>
<key>StandardInPath</key>
<string>/tmp/nspasteboardlaunchd.log</string>
<key>StandardOutPath</key>
<string>/tmp/nspasteboardlaunchd.log</string>
<key>StandardErrorPath</key>
<string>/tmp/nspasteboardlaunchd.log</string>
</dict>
</plist>
all:
gcc -o nspasteboardlaunchd nspasteboardlaunchd.m -framework appkit
install:
chmod u+x nspasteboardlaunchd
cp nspasteboardlaunchd /tmp
sudo cp dev.qkdreyer.nspasteboardlaunchd.plist /Library/LaunchDaemons/
sudo launchctl load /Library/LaunchDaemons/dev.qkdreyer.nspasteboardlaunchd.plist
uninstall:
rm /tmp/nspasteboardlaunchd
sudo launchctl unload /Library/LaunchDaemons/dev.qkdreyer.nspasteboardlaunchd.plist
sudo rm /Library/LaunchDaemons/dev.qkdreyer.nspasteboardlaunchd.plist
start-without-launchd:
/tmp/nspasteboardlaunchd
start-with-launchd:
sudo launchctl start dev.qkdreyer.nspasteboardlaunchd
sleep 5
cat /tmp/nspasteboardlaunchd.log
sudo rm /tmp/nspasteboardlaunchd.log
#import <AppKit/AppKit.h>
int main()
{
NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
NSLog(@"PasteboardName %@ PasteboardCount %lu", [pasteboard name], [pasteboard changeCount]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment