Sample Script 7

Script that will take an entry from a pop-up folder list and check the matching check-mark folder while un-checking the non-matching ones . See Notes below.

Code

  1. function SetCategoryFolder(item_id)
  2. tCategories={"Car","Computer","Duty","Education","Family","Finance","Fun","Health","Home","Investment","JobSearch","JobDo","Legal","Tax","Make$","Other","UnAssigned"}
  3. Category=get_folder_value("Category", item_id)
  4. if Category~="" then
  5. for index,TestCategory in ipairs(tCategories) do
  6. CurrCategory=get_folder_value("Category", item_id)
  7. if CurrCategory==TestCategory then
  8. set_folder_value(CurrCategory,item_id,1)
  9. else
  10. set_folder_value(TestCategory,item_id,0)
  11. end
  12. end
  13. else
  14. set_folder_value("UnAssigned",item_id,1)
  15. set_folder_value("Category",item_id,"UnAssigned")
  16. end

Code Description

  1. the laucmd.lua header for the script (function)
  2. set up a list of categories in a tCategories Table. Note: these values should be the same as the Category check-mark folders and the pop-up values in the pop-up folder (see Notes 1 & 2 below)
  3. assign the variable Category the current item's Category pop-up value (e.g. "Computer")
  4. conditional if statement to determine if the Category variable is empty ("")
  5. if Category has a value (is not empty), then iterate over all Categories in the tCategories Table Note: the index variable contains the Table index, and TestCategory variable contains the corresponding Category value (e.g. "Car" for the first index)
  6. assign the variable CurrCategory the current item's Category pop-up value (e.g. "Computer")
  7. conditional if statement to determine if the item's pop-up value (e.g. "Computer") matches the current (during the iteration) Table value (e.g. "Car")
  8. if it does, then the check-mark folder in the CurrCategory variable is set to 1 (true or checked)
  9. the else statement for conditional on line 7, and if line 7 is false then
  10. set the check-mark folder in the TestCategory variable to 0 (false or unchecked). Note that this will un-check all check-mark folders except the matching one as the Table is iterated.
  11. end of conditional on line 7
  12. end of the loop on line 5
  13. the else statement for the conditional on line 4
  14. set the item's check-mark folder "Unassigned" to 1 or checked. Note: This means that no Category has been assigned by the user
  15. also set the item's pop-up "Category" folder value to "Unassigned" Note: This means that no Category has been assigned by the user
  16. the end statement for the function on line 1

Notes


  1. Create several Category folders as check-mark folders (e.g. "Car","Computer","Duty", etc)
  2. Create a Popup Folder called "Categories" with values corresponding to the same Categories as the check-mark folders
  3. Create a text file "luacmd.lua" in the Ecco program directory (if it does not already exist)
  4. Add the function/Script as shown in the code above (w/o the numbers) to "luacmd.lua" file and save (The Script lists examples of Categories - modify as desired).
  5. In any folder (I have a check-mark folder called "LUA Scripts"), create the following rule (The rule will call the function in the "luacmd.lua" file as soon as an item is added or changed):
    ++:L:SetCategoryFolder(item_id)
  6. How it works:

Contributors


This script is taken from the http://tech.groups.yahoo.com/group/ecco_pro/message/7270 thread started by Jim Witherspoon and with the assistance of the following:

Jim Witherspoon
rbrandis
Albert Schepers
viking