--[[ NoteCase Pro script See http://www.notecasepro.com/ SCRIPT NAME: RemoveTagged-Untagged.lua Version 1.1 PURPOSE: This script throws a menu offering the user a choice between removing all tagged nodes from the List Pane or removing all untagged nodes, thus enabling further manual or scripted processing of these two types of notegroups; e.g., systematically tagging all untagged nodes. USAGE INSTRUCTIONS: List all nodes using the Notes Menu "List All Notes" action. Then run this script and select the menu item for the desired action. RIGHTS: This script's authors, Paul E. Merrell and Miroslav Rajcic, hereby waives all copyright and related or neighboring rights to this script, pursuant to the Creative Commons CC0 Universal relinquishment of rights found at http://creativecommons.org/publicdomain/zero/1.0/ CHANGE LOG: v. 1.1 * fix: adapted the script after NoteCase Pro switched from embedding of Lua v. 5.1 to Lua v. 5.2. Lua 5.1's table.getn is no longer supported, which blocked this script from executing. * remove: some code no longer needed because of later enhancements in NoteCase Pro behavior. Script now runs substantially faster. --]] -- make sure app version supports necessary scriptable program commands nMaj, nMin, nRev = Nc_Config_GetAppVersion() if (nMaj < 3 or (nMaj == 3 and nMin < 1) or (nMaj == 3 and nMin == 1 and nRev < 5)) then Nc_GUI_MessageBox("ERROR: Script requires NcPro version >= 3.1.5") return end -- load lines to table function function lines(str) local t = {} local i, lstr = 1, #str while i <= lstr do local x, y = string.find(str, "\r?\n", i) if x then t[#t + 1] = string.sub(str, i, x - 1) else break end i = y + 1 end if i <= lstr then t[#t + 1] = string.sub(str, i) end return t end -- get document ID for current document nDocID = Nc_Doc_ID_GetCur() -- get count of notes in list and store as variable nListCount local nListCount = Nc_App_List_GetCount(nDocID) -- check to see if list is empty and if so abort assert(nListCount ~= "", "ERROR: List Pane is empty") -- get user's choice -- remove tagged or untagged notes local nChoice = Nc_GUI_SelectionDlg("Remove Tagged/Untagged Notes", "Remove Tagged Notes", "Remove Untagged Notes") -- Check if user canceled selection and if so abort the script if nChoice == -1 then return end -- create empty string variables to store IDs for tagged and untagged notes strTagged = "" strNotTagged = "" -- for each note in the List Pane, do for i=1,nListCount do --get note ID and store as strListNoteID strListNoteID = Nc_App_List_Note_GetID(i-1) -- get the note's tags, if any strNoteTags = Nc_Note_Tags_Get(nDocID, strListNoteID) -- test whether note has tags and categorize and concatenate its ID into strNotTagged or strTagged variable depending on the result if strNoteTags == "" then strNotTagged = strNotTagged .. strListNoteID .. "\n" else strTagged = strTagged .. strListNoteID .. "\n" end -- end if end -- end for -- get IDs for user's choice of notes to remove if nChoice == 0 then strNotesToRemove = strTagged else strNotesToRemove = strNotTagged end -- break string into table of lines buf = lines(strNotesToRemove) -- Remove from the List Pane each note with an ID matching an ID stored in the strNotesToRemove variable local nSize = #buf for i=1, nSize do Nc_App_List_RemoveNote(buf[i]) end -- end script