I'm using this macro to scale my pgfplots to a desired size:
\newsavebox{\measuredSize}
\newcounter{int}
\newcommand{\resizeToMeasure}[3]{%
\pgfmathsetmacro{\pgfplotswidthtarget}{#2}%
\pgfmathsetmacro{\pgfplotswidth}{#2}%
\pgfmathsetmacro{\pgfplotsheighttarget}{#3}%
\pgfmathsetmacro{\pgfplotsheight}{#3}%
\setcounter{int}{1}%
\loop%
\addtocounter{int}{1}%
\begin{lrbox}{\measuredSize}%
\tikzset{external/export next=false,external/optimize=false}%
\input{#1}%
\end{lrbox}%
\pgfmathsetmacro{\pgfplotswidth}{\pgfplotswidth+\pgfplotswidthtarget-\wd\measuredSize}%
\pgfmathsetmacro{\pgfplotsheight}{\pgfplotsheight+\pgfplotsheighttarget-\ht\measuredSize}%
\ifnum \value{int}<\nIter
\repeat
\filename@parse{#1}
\tikzsetnextfilename{\filename@base}
\input{#1}}
However, when recompling without making changes to a pgfplots file I don't want to loop over that file again but just use the created pdf from the external library. So I thought it would be a nice idea to make a manual check for that file and omit the loop once the file is up to date.
In the library source code I found that \def\tikzexternal@externalizefig@systemcall@uptodatecheck#1 makes that check and takes the content of the tikzpicture as the argument #1. Now my problem is, I cannot find out how the library reads the tikzpicture to put it in that function.
Here's a MWE:
\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{filecontents}
\usetikzlibrary{external}
\makeatletter
\newsavebox{\measuredSize}
\newcounter{int}
\newcommand{\resizeToMeasure}[3]{%
\pgfmathsetmacro{\pgfplotswidthtarget}{#2}%
\pgfmathsetmacro{\pgfplotswidth}{#2}%
\pgfmathsetmacro{\pgfplotsheighttarget}{#3}%
\pgfmathsetmacro{\pgfplotsheight}{#3}%
\setcounter{int}{1}%
\loop%
\addtocounter{int}{1}%
\begin{lrbox}{\measuredSize}%
\tikzset{external/export next=false,external/optimize=false}%
\input{#1}%
\end{lrbox}%
\pgfmathsetmacro{\pgfplotswidth}{\pgfplotswidth+\pgfplotswidthtarget-\wd\measuredSize}%
\pgfmathsetmacro{\pgfplotsheight}{\pgfplotsheight+\pgfplotsheighttarget-\ht\measuredSize}%
\ifnum \value{int}<5
\repeat
\filename@parse{#1}
\tikzsetnextfilename{\filename@base}
\input{#1}}
\makeatother
\begin{document}
\begin{filecontents}{tikzpicture01.tikz}
\begin{tikzpicture}
\begin{axis}[
height=\pgfplotsheight,
width=\pgfplotswidth
]
\addplot coordinates {
( 1.5, 1.28 )
( 1.75, 1.43 )
( 2.0, 1.59 )
( 2.25, 1.75 )
( 2.5, 1.91 )
( 2.75, 2.07 )
( 3.0, 2.23 )
};
\end{axis}
\end{tikzpicture}
\end{filecontents}
\resizeToMeasure{tikzpicture01.tikz}{7cm}{7cm}
\end{document}