This is a follow-up question of Add section titles to list of frames.
As you can see in the minimal example below I call the same macro after every \section and I'd like to automize it. I basically tried every command provided by etoolbox (\apptocmd, \appto, \gappto, \csappto, etc.), but got none of them working. Which one is the right one and how should it be used? Or are there other solutions?
\documentclass{beamer}
\usepackage{hyperref}
\usepackage{etoolbox}
\makeatletter
\newcommand\listofframes{\@starttoc{lbf}}
\makeatother
\makeatletter
\addtobeamertemplate{frametitle}{}{%
\mode<presentation>
{
\only<1>{
\hypertarget{\insertframetitle}{}%
\addcontentsline{lbf}{section}{\protect\makebox[2em][l]{%
\protect\usebeamercolor[fg]{structure}\scriptsize\insertframenumber\hfill}%
\ifx\insertframesubtitle\@empty%
\scriptsize\protect\hyperlink{\insertframetitle}{\insertframetitle}%
\else%
\scriptsize\protect\hyperlink{\insertframetitle}{\insertframesubtitle}%
\fi%
\par}%
}
}
}
\makeatother
\newcommand{\sectioninlbf}{
\addcontentsline{lbf}{section}{%
\vspace{0.3\baselineskip}
\protect\footnotesize%
\secname\par}%
}
\begin{document}
\begin{frame}
\frametitle{General outline}
\tableofcontents[hideallsubsections]
\end{frame}
\begin{frame}
\frametitle{List of Frames}
\listofframes
\end{frame}
\section{Test section one}\sectioninlbf
\begin{frame}
\frametitle{Test Frame One}
test
\end{frame}
\section{Test section two}\sectioninlbf
\begin{frame}
\frametitle{Test Frame Two}
\framesubtitle{Test Frame Two Subtitle}
test
\end{frame}
\begin{frame}
\frametitle{Test Frame Three}
\uncover<1->{test}
\uncover<2->{test}
\uncover<3->{test}
\end{frame}
\end{document}

