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.
-
Related and possible duplicate: Keyboard shortcut for service only works after I manually run the service – klanomath Jan 30 '17 at 11:17
1 Answers
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.workflow
points 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
~/Library/LaunchAgents/me.myname.launchmyservice.sh
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.sh
so 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

- 889
-
This answer doesn't really apply to the question. The problem of the OP is probably a bug in macOS. Your answer may even work in some cases because the service is force-executed while logging in. Depending on the service this may result in unintended consequences though. – klanomath Feb 06 '17 at 02:17
-