Shell scripts and user defaults

I have 2 text fields. One called “source” and one called “destination”. I want to run a shell script and have the script use the contents of those 2 fields in the script.
I do have bindings on both fields but I can’t get anything to work. I am a noob.

Is this something I can do? If so, please help!


Model: Powerbook G4
Browser: Safari 523.10.6
Operating System: Mac OS X (10.5)

Let’s see if I can help. If I’m wrong, then someone correct me :smiley:

For the Textfield in IB, select it and then go Bindigs and tick to bind it to “Value.” Select “Shared Defaults” from the drop-down. Set the model key path to mkpSource or mkpDestination depending on what Textfield you are currently binding.

Then in the AppleScript file, add this:

on should quit theObject
	tell user defaults
		make new default entry at end of default entries with properties {name:"mkpSource", content:""}
		make new default entry at end of default entries with properties {name:"mkpDestination", content:""}
	end tell
	call method "synchronize" of object user defaults
end should quit

You can change the “On should Quit” to anything similar. Ex.:

on will finish launching theObject
-- Bla Bla Bla
end will finish launching

Hope that helps.

Thanks guimkie but I worded my question wrong.

What I was actually asking was how I reference the contents of those fields in my “do shell script”

For a better example, lets say I was trying to copy my desktop into a folder called “Desktop2”.
Hard-coded, it would be like:
do shell script “cp -a /Users/Desktop/ /Users/Desktop2/”

But I want to use the contents of my 2 text fields as my source and destination (source would be /Users/Desktop and destination would be /Users/Desktop2. So that would be more like this:
do shell script “cp -a SOURCE DEST”

How would I get the script to use the contents of those two text fields.

Clear as mud? :stuck_out_tongue:

User defaults are more for saving values between runs. You don’t have to use the user defaults class when in your script; You can just access the fields directly.

Try something like this:

set sourcePath to content of text field "whatever" of window "whatever"
set destinationPath to content of text field "whatever" of window "whatever"

do shell script "/bin/cp -a " & quoted form of sourcePath & " " & quoted form of destinationPath

No, it’s very confusing. Using cp is something completely different.

If the content of any text field is bound to user defaults, you can get the value with

do shell script "defaults read [domain] [key]"

[domain] is the bundle identifier without the plist extension, default location is ~/Library/Preferences (e.g.
[key] is the key of the text field you used to bind the value

Bruce, you nailed it!:smiley: Thanks so much for the help!

StefanK, thank you for the clarification. I learned something from that as well.

Thanks so much for the help.