Move current file in Preview.app to ~/Dropbox/Photos/

I’m trying to move the currently open file in Preview to ~/Dropbox/Photos/

I am terrible at AppleScript, so I’ve just pasted this together from Google searches:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

try
	
	tell document 1 of application "Preview"
		set theFile to path
	end tell
	
	POSIX file theFile
	
	tell application "Finder"
		move theFile to folder (POSIX file ((path to home folder as string) & "Dropbox:Photos"))
	end tell
	
end try

I get no error messages, but the file is not moved.

What did I do wrong now?

Thanks

I would try to edit an instruction as

	set theFile to POSIX file theFile

Ah, lovely. That works. Thank you.

However, I noticed that when I move a file in this manner, Preview.app still shows it as being in the original location and the file is now listed as being “locked”.

  1. Is there a way to move the file and have the new location reflected in Preview.app?

  2. Failing that, I would assume that I need to do the following:

  • Close the file in Preview
  • Move the file
  • Re-Open the file from its new location

Which isn’t very elegant, but might be my only option.

If #2 is the way to do, I thought this might do it

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

try
	
	tell document 1 of application "Preview"
		set theFile to path
		close
	end tell
	
	set theFile to POSIX file theFile
	
	tell application "Finder"
		move theFile to folder ((path to home folder as string) & "Dropbox:Photos")
	end tell
	
	set theNewFile to file ((path to home folder as string) & "Dropbox:Photos" & theFile)
	
	set theNewFile to POSIX file theNewFile
	
	tell application "Preview"
		open theNewFile
	end tell
	
end try

but although this does move the file to Dropbox and does close the file in Preview, it does not re-open the file in the new location. If I had to guess, I am probably not setting theNewFile properly, but I’m not sure how to do is correctly.