I'm using MiKTeX 2.9 on a Windows 7 Home Premium 64-bit computer.
I have been experimenting with using attachfile2 to make a link to an embedded LaTeX file. When I compile the following document, named test.tex,
\documentclass{article}
\usepackage{xcolor}
\definecolor{myred}{rgb}{0.9,0.2,0.2}
\usepackage{attachfile2}
\attachfilesetup{color = myred}
\begin{document}
\jobname.tex \textattachfile{test.tex}{view source code}
\end{document}
it works as expected, producing the name of the file and a link:

But when I replace test.tex with \jobname.tex in the \textattachfile command, I get the following error (I am using TeXstudio 2.6.2):

Even putting \expandafter right before \textattachfile, which as far as I understand should ensure that \textattachfile never even sees the command \jobname, doesn't help.
What's going on?
Further observations (not sure if relevant):
When I use
attachfileinstead ofattachfile2, it works fine with the\jobnameinput (of course, the only difference being that I can't use my custom color, which is the reason I wanted to useattachfile2in the first place).As I mentioned, I'm using TeXstudio. This editor has a convenient feature where it (at least attempts to) detect the commands that are defined by any included packages, and then highlights any commands it doesn't recognize. When I use the
attachfilepackage, the commands\attachfilesetupand\textattachfileare recognized; when I use theattachfile2package, they are not recognized. Perhaps my copy of theattachfile2package is broken somehow? MiKTeX tells me that I have theoberdiekbundle installed, which is apparently whereattachfile2lives.I also tried using the
currfilepackage, which provides a macro\currfilename. Nothing different happens when I replace\jobname.texwith\currfilename; it works and doesn't work in the same cases.