# The attachfile2 package doesn't work when using \jobname

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 attachfile instead of attachfile2, it works fine with the \jobname input (of course, the only difference being that I can't use my custom color, which is the reason I wanted to use attachfile2 in 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 attachfile package, the commands \attachfilesetup and \textattachfile are recognized; when I use the attachfile2 package, they are not recognized. Perhaps my copy of the attachfile2 package is broken somehow? MiKTeX tells me that I have the oberdiek bundle installed, which is apparently where attachfile2 lives.

• I also tried using the currfile package, which provides a macro \currfilename. Nothing different happens when I replace \jobname.tex with \currfilename; it works and doesn't work in the same cases.