Applescript to move script file to another folder and back?

For reasons that will be clear to experienced scripters who have worked with macOS Sierra, it will be useful to be able to make an Applescript application move itself to a different folder (via the Finder, not a shell command) and then move itself back again (again using the Finder). (Search “AppTranslocation” online for details.) It’s easy to write a script that moves itself to a different folder, but I can’t figure out how to make it move back again. I’ll be grateful for any help.

Here’s a script that moves itself to a different folder, choosing a different folder depending on where it is now. The script should be saved to disk before you run it.

set myPath to (path to me) as text
set appPath to (path to applications folder) as text
set deskPath to (path to desktop) as text
set userPath to (path to home folder) as text

if myPath contains "Desktop" then
	set targetPath to userPath
	set targetText to "your home"
else if myPath contains "Applications" then
	set targetPath to deskPath
	set targetText to "Desktop"
else if myPath contains userPath then
	set targetPath to deskPath
	set targetText to "Desktop"
else
	set targetPath to "Desktop"
	set targetText to deskPath
end if

display dialog "Move me to " & targetText & " folder?" buttons {"Yes", "No"}

if button returned of result is "Yes" then
	tell application "Finder" to move file myPath to targetPath
end if

What I can’t figure out is how to put together a path that I can use to tell the Finder to move the script back again. This is probably obvious to every expert, but I haven’t been able to come up with an answer.

Hi. You need to retain info about where the file originally lived. I made a few other minor changes, as the text coercions and some of the if considerations seemed unnecessary.

set myPath to (path to me)
set appPath to (path to applications folder)
set deskPath to (path to desktop)
set userPath to (path to home folder)

tell myPath as text to if it contains "Desktop" then
	set targetPath to userPath
	set targetText to "your home"
else
	set targetPath to deskPath
	set targetText to "Desktop"
end if

display dialog "Move me to " & targetText & " folder?" buttons {"Yes", "No"}

if button returned of result is "Yes" then
	tell application "Finder"
		set sourceLocus to myPath's container --file's origin
		set resituated to (move myPath to targetPath) as alias --file at destination
		delay 3 --for demonstration purposes
		move resituated to sourceLocus
	end tell
end if

This is perfect. Thank you. I was banging my head on the desk trying to figure out the correct syntax for the line:

set sourceLocus to myPath's container

Everything I tried was far too complicated, and I had no idea it was so straightforward.