Create a variable that refers to the string name of the current animation. Connect the AnimatedSprite's animation_finished signal to a function:
$AnimatedSprite.connect("animation_finished", self, "name_of_function")
The function can check if the variable == "attack1" and then change it to "idle" if so. This requires replacing the string literals referring to the animations with the variable, which will be changed whenever you want to change animations.