I have an applescript that I run like a cron job. Within this applescript, i have variables that act like boolean switches (i.e. on/off values). With subsequent runs, depending on whether the boolean variables' values are on/off i need to take certain actions.
Q) What are the different ways this can be done? (would appreciate sample code).
Cheers.
Answer) plist or property files seem to be the way to go.
credit to daviesgeek for pointing me in the right direction. for those interested i've written helper sub-routines as follows:
-- read the plist file
tell application "System Events"
tell property list file plistfile_path
tell contents
set someLocalVariable to value of property list item "someLocalVariable"
end tell
end tell
end tell
on create_plist_file(file_path)
-- create the 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 this_plistfile to ¬
make new property list file with properties {contents:parent_dictionary, name:file_path}
-- add new property list items of each of the supported types
make new property list item at end of property list items of contents of this_plistfile ¬
with properties {kind:boolean, name:"someLocalVariable", value:false}
-- make new property list item at end of property list items of contents of this_plistfile ¬
-- with properties {kind:string, name:"stringKey", value:"string value"}
end tell
end create_plist_file
on set_someLocalVariable(bool_val)
tell application "System Events"
tell property list file plistfile_path
tell contents
set value of property list item "someLocalVariable" to bool_val
end tell
end tell
end tell
end set_wasAllTransfersStarted
Best Answer
You can write to a .plist file as such:
This script will ask for the user's browser and it will save it across runs of the script.