@Override
    public void run() {
        monitor.setMessage("Counting symbols...");
        SymbolTable st = state.getCurrentProgram().getSymbolTable();
        SymbolIterator iter = st.getSymbolIterator(true);
        int count = 0;
        while (iter.hasNext() && !monitor.isCancelled()) {
            Symbol sym = iter.next();
            if (sym != null) {
                println(sym.getName());
                count++;
            }
        }
        println(count+" symbols");
    }
@see ghidra.app.script.GhidraScript#run()
Ghidra/Features/Base/ghidra_scripts/CountSymbolsScript.java