Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Sep 21, 2010, 06:25 PM   #1
BollywooD
macrumors 6502
 
Join Date: Apr 2005
Location: Surfers Paradise
Defaults, and Shell scripts

so I am trying to copy keys from one plist to another, and the following command works well from the command line:
Code:
defaults write com.sweetpproductions.SafariCookies `defaults read com.apple.Safari SCautomaticMode`
whereas the following post-install shell script does not?
Code:
#!/bin/sh


# remove unneeded defaults
#find all users
for arg in `ls /Users`
do

#copy preferences for all users, if it exists - ignoring the Shared folder
if [ $arg != 'Shared' ]; then
	/usr/bin/su $arg -c "/usr/bin/defaults write com.sweetpproductions.SafariCookie `/usr/bin/defaults read com.apple.Safari SCautomaticMode`"
	
fi
done
exit 0
I get the following error:
Code:
22/09/10 7:55:48 AM	defaults[895]	
Rep argument is not a dictionary
Defaults have not been changed.
can anyone tell me what I am doing wrong?

thanks in advance.
BollywooD is offline   0 Reply With Quote
Old Sep 21, 2010, 07:38 PM   #2
chown33
macrumors 603
 
Join Date: Aug 2009
Just a guess...

The man page for bash says this about double-quotes:
Enclosing characters in double quotes preserves the literal value of
all characters within the quotes, with the exception of $, `, and \.
The characters $ and ` retain their special meaning within double
quotes. ...
(Underline added for emphasis.)
So the backtick-delimited command is being evaluated from a different context. You might want to use the -x bash option, like so:
Code:
set -x
This will tell bash to echo the command-line before executing it.
chown33 is offline   0 Reply With Quote
Old Sep 22, 2010, 08:54 PM   #3
BollywooD
Thread Starter
macrumors 6502
 
Join Date: Apr 2005
Location: Surfers Paradise
Quote:
Originally Posted by chown33 View Post
You might want to use the -x bash option, like so:
Code:
set -x
This will tell bash to echo the command-line before executing it.

I tried, but it didn't work, but you got me on the right path, all I had to do was to escape the single quotations like so:
Code:
/usr/bin/su $arg -c "/usr/bin/defaults write com.sweetpproductions.SafariCookie \`/usr/bin/defaults read com.apple.Safari SCautomaticMode\`"
and it works great, thanks for the help.
BollywooD is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Wi-Fi network defaults Rampant.A.I. iPhone Tips, Help and Troubleshooting 0 Feb 5, 2014 07:12 PM
Defaults kenglade Mac Basics and Help 0 Nov 5, 2013 08:38 AM
Back to defaults... jtfolden OS X Mavericks (10.9) 2 Oct 13, 2013 02:39 AM
iOS 7 Defaults dai.hop iOS 7 9 Sep 25, 2013 05:07 AM
iTunes Library defaults to HD Imacmatches OS X 10.8 Mountain Lion 2 Jul 4, 2013 10:58 AM

Forum Jump

All times are GMT -5. The time now is 07:45 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC