3

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.

1

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)

  1. 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
    
  2. Save the file, e.g. as ~/Library/LaunchAgents/me.myname.launchmyservice.sh

  3. 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

  1. 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>
    
  2. Save the text file to ~/Library/LaunchAgents/me.myname.update-desktop-from-webcam.plist – the name should match the "Label" key in the file.

  3. Load it by issuing the following command:

    launchctl load ~/Library/LaunchAgents/me.myname.update-desktop-from-webcam.plist
    
|improve this answer|||||
  • 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 6 '17 at 2:17
  • It didn't work :( – Tolga Ozses Feb 6 '17 at 6:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .