-- awaynick script for Colloquy -- edited to go back to default nick by 31d1 -- use /defnick /awaynick /awaytime property prefs : missing value property prefsPath : missing value property idletime : 0 script prefsTemplate property defaultKeys : {¬ {label:"maxidletime", value:600}, ¬ {label:"awaynick", value:"away"} ¬ } property theKeys : defaultKeys property build : 1 --increment each time you change something where prefs needs to change --returns true if the value was found, false if the value had to be created on setKey(thisLabel, newValue) repeat with k in theKeys if label of k is thisLabel then set value of k to newValue return true end if end repeat set theKeys to theKeys & {{label:thisLabel, value:newValue}} return false end setKey on getKey(thisLabel) repeat with k in theKeys if label of k is thisLabel then return value of k end if end repeat return missing value end getKey on listKeys() set final to "" repeat with k in theKeys set final to final & label of k & ": " & (value of k as string) & return end repeat return final end listKeys end script on loadPrefs() if prefs is missing value then set prefsPath to (path to preferences folder from user domain as Unicode text) & "Colloquy AwayNick Prefs" try set prefs to load script alias prefsPath try set oldbuild to build of prefs on error set oldbuild to -1 end try if oldbuild < build of prefsTemplate then set newPrefs to prefsTemplate set newPrefs to my mergeKeys(prefs, prefsTemplate) set prefs to newPrefs my savePrefs() end if on error set prefs to prefsTemplate end try end if end loadPrefs on savePrefs() if prefs is not missing value then store script prefs in file prefsPath replacing yes end savePrefs on mergeKeys(oldPrefs, newDefaultPrefs) try repeat with k in theKeys of newDefaultPrefs set oldvalue to oldPrefs's getKey(label of k) if oldvalue is not missing value then set value of k to oldvalue end if end repeat end try return newDefaultPrefs end mergeKeys using terms from application "Colloquy" on idle set idletime to idletime + 1 my loadPrefs() tell prefs to set mit to getKey("maxidletime") tell prefs to set an to getKey("awaynick") if idletime > mit then repeat with thisConn in every connection set nickname of thisConn to an end repeat end if return 1 end idle on process outgoing chat message theMessage my loadPrefs() tell prefs to set dn to getKey("defnick") tell prefs to set mit to getKey("maxidletime") if idletime > mit then repeat with thisConn in every connection set nickname of thisConn to dn end repeat end if set idletime to 0 return theMessage end process outgoing chat message on build contextual menu for item set idletime to 0 return {} end build contextual menu for item