Simple Move File

How can I move a specific file in a folder to another folder?

Does it help to have the file name? I have the filename in a filemaker field, how can I use that to move the specific file?


Try code like follows:

set sourcefilename to "test.rtf"
set sourcefolderpath to "Macintosh HD:Users:martin:Desktop:Source:"
set sourcefilepath to (sourcefolderpath & sourcefilename) as text

set destfolderpath to "Macintosh HD:Users:martin:Desktop:Destination:"

-- using the Finder
tell application "Finder"
	move (sourcefilepath as alias) to (destfolderpath as alias) with replacing
end tell

-- using the shell
(*set destfilepath to (destfolderpath & sourcefilename) as text
set command to "mv " & quoted form of POSIX path of sourcefilepath & " " & quoted form of POSIX path of destfilepath
do shell script command*)

There are a few things to know, some limitations, about getting a value from a FileMaker field. A FileMaker file can have several base tables, and several layouts. You have to tell it what/where the field is. Unless the field is on the current layout of the frontmost window; that is the default if you don’t use a more specific location for it. If you are running this from an external AppleScript.

tell application “FileMaker Pro Advanced”
set first_name to cell “Name_first” of current record
end tell

If you are running this within a FileMaker Perform AppleScript step, then you do not need/want: tell application “FileMaker Pro”. FileMaker knows who it is. Usually I write the AppleScript in Script Editor, then just comment out those lines after copy/pasting in the Perform AppleScript (native).

There is another option in Perform AppleScript, to run an AppleScript which is a calculation, or a calculation field (or a combo of the two). That is sometimes easier, as far as getting the FileMaker data, but requires you to explicitly add quotes and returns at the end of lines; which makes it a real PITA for long AppleScripts.

You can also specify a FileMaker field via its layout or table (this is NOT a FileMaker “base table”, it is the name of a “table occurrence” on the Relationship Graph. You can never specify or see a base table name in FileMaker; it is always the Relationship Graph (which may very well have occurrences from other files). But in AppleScript you use the term “table” for this (and the terms are often used interchangeably in documentation, which increases the confusion).

Personally, if a beginner, I say create a dedicated FileMaker layout for the fields you need, unless they are already on the layout when you want to run the AppleScript. Then Freeze Window, Go to Layout, the layout. Or use AppleScript to tell it to go to the layout. This is also safer, as it does not require hard-coded names of layouts or table occurrences within the AppleScript.

FileMaker used to install AppleScript documentation, but no longer does so (a mistake, IMHO). This is a link to it. It is important to know the object hierarchy. Do not assume that “document” and “window” when referenced by its number are the same thing, for example.

Browser: Safari 523.12
Operating System: Mac OS X (10.6)