AppleScript: Toggling PLIST values

Discussion in 'Mac Programming' started by Caleb531, Nov 14, 2009.

  1. Caleb531 macrumors 6502


    Oct 17, 2009
    I am trying to create an AppleScript, which will toggle a preference in an application called Anxiety. I am doing this through the PLIST file, and when I open the file in Property List Editor, the value is a checkbox.

    The code below is what I am trying. It doesn't work because the value isn't TRUE or FALSE, it's a checkbox, and I don't know how to toggle that. Any help would be greatly appreciated!

    set toggle to do shell script "defaults read com.modelconcept.Anxiety hideOnDeactivate"
    if toggle = "TRUE" then
    do shell script "defaults write com.modelconcept.Anxiety hideOnDeactivate FALSE"
    do shell script "defaults write com.modelconcept.Anxiety hideOnDeactivate TRUE"
    end if
    end try
  2. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    The values aren't "TRUE" and "FALSE". Use this discovery process to learn what the values are:

    1. Open the plist file in Property List Editor.
    2. Make sure the checkbox is unchecked.
    3. Save.
    4. In Terminal, enter the command below [see Note 1].
    5. Note the output as the value representing "unchecked".
    6. In PList Editor, check the checkbox.
    7. Save.
    8. In Terminal, enter the same command again.
    9. Note the output as the value representing "checked".
    10. Write your AppleScript to use the values noted.

    To summarize: set a known value using PList Editor (only two are possible), observe the value using the 'defaults' command, use the observed values to write your script.

    Note 1:
    defaults read com.modelconcept.Anxiety hideOnDeactivate

Share This Page