< Zurück

02.12.2012 22:01:00 • Categories: Applescript • Tags: Applescript

AppleScript: System Events - writing to plist-file

tell application "System Events"
    -- create an empty property list dictionary item
    set the parent_dictionary to make new property list item with properties {kind:record}
    -- create new property list file using the empty dictionary list item as contents
    set the plistfile_path to "~/Desktop/example.plist"
    set pl to make new property list file with properties {contents:parent_dictionary, name:plistfile_path}
    -- add the values to plist
    tell pl
        -- create a text entry
        make new property list item at end with properties {kind:string, name:"testtext", value:"This is some text"}
    -- create a truth value entry
    make new property list item at end with properties {kind:boolean, name:"testbool", value:true}

    -- create an integer entry
    make new property list item at end with properties {kind:number, name:"testinteger", value:250}

    -- create a float / real entry
    make new property list item at end with properties {kind:number, name:"testfloat", value:123.456789}

    -- create an empty dictionary
    set r to make new property list item at end with properties {kind:record, name:"testdictionary"}

    -- fill that dictionary
    tell r
        -- some string whith non ASCII characters
        make new property list item at end with properties {kind:string, name:"danish_island", value:"XY"}

        -- some date entry
        make new property list item at end with properties {kind:date, name:"now", value:current date}

        -- create an array (or list)
        make new property list item at end with properties {kind:list, name:"testarray", value:{123, "abc", 100}}
    end tell
end tell

end tell

(another example to write an plist-file) set plistfile_path to "~/Desktop/example_2.plist" set the_record to {testbool:true, testinteger:250, testdictionary:{danish_island:"XY", now:date "Donnerstag, 16. Juni 2011 14:38:04", testarray:{123, "abc", 100}}, testtext:"This is some text", testfloat:123.456789} tell application "System Events" set the parent_dictionary to make new property list item with properties {kind:record, value:the_record} set pl to make new property list file with properties {contents:parent_dictionary, name:plistfile_path} end tell

 


< Zurück | ^ nach oben