Moving file to a system folder

When making a custom System Settings panel, I want the project to automatically move the prefpane file to /Library/PreferencePanes/. With Run Script, the build fails because of denial to perform the operation. Sudo doesn't help, too.

PREFPANE_SRC="${BUILT_PRODUCTS_DIR}/App.prefPane" PREFPANE_DST="$HOME/Library/PreferencePanes/"

echo "PrefPane source path: $PREFPANE_SRC" echo "PrefPane destination path: $PREFPANE_DST"

if [ -d "$PREFPANE_SRC" ]; then echo "Installing preference pane to ${PREFPANE_DST}" cp -R "${PREFPANE_SRC}" "${PREFPANE_DST}" else echo "Preference pane not found: ${PREFPANE_SRC}" exit 1 fi

Answered by DTS Engineer in 801926022

It’d help if you post this stuff as text rather than screen shots. It’s much harder for me to see what’s going on from a screen shot. For this and other tips, see Quinn’s Top Ten DevForums Tips.

You can get the text of a build step failure from the Reports navigator. I talk about this, in a different context, in Command [something] failed with a nonzero exit code.

However, it looks like things are failing with Operation not permitted, which is EPERM. That suggests a sandbox issue. Do you have the User Script Sandboxing build setting enabled?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I want the project to automatically move the prefpane file to /Library/PreferencePanes/.

Does it have to be /Library/PreferencePanes/? From a privileges perspective, ~/Library/PreferencePanes/ is much easier.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

The project compiles with ~/Library/PreferencePanes/, but the menu doesn't appear in System Settings.

Even if you quit and relaunch?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Even if you quit and relaunch?

Yes, even in that case. Here is a screenshot of the Build Log. Also the ~/Library/PreferencePanes/ folder in Finder doesn't have the file.

This is the script:

PREFPANE_SRC="${BUILT_PRODUCTS_DIR}/Dynamic Notch.prefPane"
PREFPANE_DST="$HOME~/Library/PreferencePanes/"

echo "PrefPane source path: $PREFPANE_SRC" 
echo "PrefPane destination path: $PREFPANE_DST"

if [ -d "$PREFPANE_SRC" ]; then 
    echo "Installing preference pane to ${PREFPANE_DST}" cp -R "${PREFPANE_SRC}" "${PREFPANE_DST}" 
    else echo "Preference pane not found: ${PREFPANE_SRC}" 
exit 1 
fi

Sorry, I'm inexperienced in macOS development and thanks for your patience!

Oh, I think I see what’s going on here. Looking at your screen shot of the build log, I see this:

PrefPane destination path: /Users/ivantonchev~/Library/PreferencePanes/

Note how the ~ is embedded in the path. That’s because your script has this:

PREFPANE_DST="$HOME~/Library/PreferencePanes/"

$HOME expands to the user’s home directory, so you don’t need the ~ (which would do the same thing if you put it outside of the quotes). Consider this:

% echo "$HOME~/Library/PreferencePanes/"        
/Users/quinn~/Library/PreferencePanes/
% echo "$HOME/Library/PreferencePanes/" 
/Users/quinn/Library/PreferencePanes/
% echo ~"/Library/PreferencePanes/" 
/Users/quinn/Library/PreferencePanes/

The first one is wrong; the second two are right.

Also, I recommend that you add a set -e to your script. That way it’ll fail if any command fails. Consider:

% cat test.sh 
#! /bin/sh

set -e

echo "before"
false
echo "after"
% ./test.sh 
before

Note how the script doesn’t print after. If you remove the set -e it will, and this continue-after-failure behaviour is quite confusing.

Oh, one last thing: Don’t copy code using cp. Use ditto instead, because it does the right thing with symlinks. And it’s best to completely remove the previous item beforehand, lest you be hit by this issue.

I'm inexperienced in macOS development

No worries. I learnt a lot of this the hard way. Let’s hope you can avoid that pain (-:

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thank you so much! There is progress. The project compiles and the file appears in ~/Library/PreferencePanes; the only issue is that when Show Package Contents is clicked there is nothing, whereas in the original location the file contains the specific files.

Tried ditto as well but didn't do anything either.

Accepted Answer

It’d help if you post this stuff as text rather than screen shots. It’s much harder for me to see what’s going on from a screen shot. For this and other tips, see Quinn’s Top Ten DevForums Tips.

You can get the text of a build step failure from the Reports navigator. I talk about this, in a different context, in Command [something] failed with a nonzero exit code.

However, it looks like things are failing with Operation not permitted, which is EPERM. That suggests a sandbox issue. Do you have the User Script Sandboxing build setting enabled?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Hi again! Sorry for the screen shots. Disabling the User Script Sandboxing fixes the issue. Thank you for your patience! Have a great day!

Moving file to a system folder
 
 
Q