A different user-defaults question.....promise

Ok, I want to access the user-defaults of an application through applescript. All the examples I see are of creating/accessing user-defaults for the application…not for another application.

My applescript will toggle Dashboard on/off, so I need to find the state of entry mcx-disabled.

You can’t really do that with the user defaults class provided by AS Studio. Can you use the defaults command line tool instead?

I can definately use it to set the value I want.

I’m not sure if I can retrieve a value for testing (not that I’ve looked that up yet). I was just wondering if user-defaults could do it.
.
.
.
.
A quick check of the man page for defaults and simply use the command “read” and it will return an integer for the boolean value (1 or 0 of course).

set dashboardState to (do shell script "defaults read com.apple.dashboard mcx-disabled")

if (dashboardState is "1") then
	do shell script "defaults write com.apple.dashboard mcx-disabled -boolean NO"
else if (dashboardState is "0") then
	do shell script "defaults write com.apple.dashboard mcx-disabled -boolean YES"
end if

tell application "Dock"
	quit
end tell

One possibly way to shorten that (minus any error handling):

do shell script "/usr/bin/defaults read com.apple.dashboard mcx-disabled"

get item ((result as integer) + 1) of {"YES", "NO"}

do shell script "/usr/bin/defaults write com.apple.dashboard mcx-disabled -boolean " & result

tell application "Dock" to quit

Arrays start at 1, so it needs to be:

get item ((result as integer) + 1) of {“YES”,“NO”}

or it indexes a non-existent position and throws an error. :slight_smile:

Sorry, I’ve been doing a little PHP lately; I’ll edit my post. :slight_smile: