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.
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