A while ago, I wrote a few services and assigned them to key combinations. The problem is, even though services are under application's File menu item, I have to invoke it manually the first time, then I can use the key combination. Is there a way to be able use services when you first launch the application? I looked at this answer, but I'd rather use a 3rd party application only if I absolutely have to.
You can make this work with launchd. This requires two steps: First creating a script that invokes your service(s), and second creating a LaunchAgent plist file that will call the script at launch.
First step: Creating a script that invokes your service(s)
Write a text file with the following content, where
~/Library/Services/myservice.workflowpoints to the service you want to start (if you want to start more than one service, repeat the second line pointing to the different services):
#!/bin/bash automator ~/Library/Services/myservice.workflow
Save the file, e.g. as
Make it executable by issuing the following command in the Terminal:
chmod u+x ~/Library/LaunchAgents/me.myname.launchmyservice.sh
Second step: Creating a LaunchAgent plist that calls the script
Write a text file with the following content. You need to adapt the string
/Users/myusername/Library/LaunchAgents/me.myname.launchmyservice.shso it points to the script created in the first step. You cannot use a relative path with
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>me.myname.launchmyservice</string> <key>ProgramArguments</key> <array> <string>/Users/myusername/Library/LaunchAgents/me.myname.launchmyservice.sh</string> </array> <key>RunAtLoad</key> <true/> </dict> </plist>
Save the text file to
~/Library/LaunchAgents/me.myname.update-desktop-from-webcam.plist– the name should match the "Label" key in the file.
Load it by issuing the following command:
launchctl load ~/Library/LaunchAgents/me.myname.update-desktop-from-webcam.plist