1

I am trying to load a workflow as a service using launchctl on macOS (Ventura 13.2.1), but I am encountering an error message. The workflow is located at /Users/rohan/Library/Services/open-bluetooth-pane.workflow/Contents/Info.plist.

When I run the command

sudo launchctl load -w /Users/rohan/Library/Services/open-bluetooth-pane.workflow/Contents/Info.plist

I get the error message "Path had bad ownership/permissions" (Load failed: 122). I have checked the permissions of the folders and files involved, but everything seems to be correct.

I set the permission using following

sudo chown -R rohan:staff /Users/rohan/Library/Services/open-bluetooth-pane.workflow
sudo chmod -R 755 /Users/rohan/Library/Services/open-bluetooth-pane.workflow

Trying to create a simple service using automator and configured it to run the applescript which in turns runs the a shell script to open the Bluetooth pane.

Here is the applescript

on run {input, parameters}
    
    do shell script "/Users/rohan/Documents/bluetooth-settings.sh"
    
    return input
end run

here is the shell script

#!/bin/bash
open /System/Library/PreferencePanes/Bluetooth.prefPane

Code inside Info.plist

?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>NSServices</key>
        <array>
                <dict>
                        <key>NSBackgroundColorName</key>
                        <string>background</string>
                        <key>NSIconName</key>
                        <string>NSActionTemplate</string>
                        <key>NSMenuItem</key>
                        <dict>
                                <key>default</key>
                                <string>open-bluetooth-pane</string>
                        </dict>
                        <key>NSMessage</key>
                        <string>runWorkflowAsService</string>
                </dict>
        </array>
</dict>
</plist>
4
  • Can you show what's inside Info.plist ? Mar 17, 2023 at 10:52
  • Also can you exmplain exactly what you want to achieve? Because I can see your script will open Bluetooth settings. Why not running it directly, but via launchctl? Mar 17, 2023 at 11:00
  • I'm creating it as service so i can add a shortcut to it, and open Bluetooth pane with keyboard shortcut, rather opening spotlight search and type Bluetooth, just saving some keystrock, since I switch Bluetooth devices frequently.
    – roanjain
    Mar 17, 2023 at 11:04
  • Update the description for code inside Info.plist
    – roanjain
    Mar 17, 2023 at 11:05

1 Answer 1

2

First of all, you don't need launchctl to assign any keyboard shortcuts. Simply create a new Shortcut in Shortcuts.app like so: Shortcuts app with open Bluetooth shell script

Here you can see, that you can assign global keyboard shortcut that will run this service.

Back to launchctl. The plist file that is loaded by launchctl is not the Info.plist file. It has a special structure like:

<?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>com.apple.Spotlight</string>
        <key>ProgramArguments</key>
        <array>
            <string>/System/Library/CoreServices/Spotlight.app/Contents/MacOS/Spotlight</string>
        </array>
        <key>KeepAlive</key>
        <true/>
</dict>
</plist>

Here is the Apple Website that explains the keys used in that plist file.

3
  • A far better approach.
    – IconDaemon
    Mar 17, 2023 at 11:30
  • This shortcut worked perfect, Thanks a lot. Just one question, it works from finder, not when I am on desktop, in vs code, in google chrome.
    – roanjain
    Mar 17, 2023 at 11:38
  • Have you selected "Services Menu" in "Details"? I can run the keyboard shortcut from any app Mar 17, 2023 at 12:50

You must log in to answer this question.

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