filemaker pro: applescript enter password

i have a copy of filemaker pro that is not completely stable on my 10.3 xserve. it was worse on 10.1, but it still randomly quits every few days. i need it to serve my website though, so until i can get the program stable, i would like to run a script that checks to see if the program is running (which i am told is easy) then opens it if not (which i am told is also easy) and then enters a password and opens the three data files (which I am told is the hard part.)

Does anyone know if filemaker pro is scriptable in this way? I am an AppleScripting novice myself, but i have a talented and experienced Perl Scripter at my disposal, could he probably handle a script of this magnitude?

thanks

Whoever’s advising you is 2/3rds correct.

1/3: Check if a program is running is easy:

tell application "System Events"
   set running_apps to name of every application process
   if running_apps contains "Filemaker Pro" then
      --- filemaker is running
   else
      --- it isn't, so restart it
   end if
end tell

2/3: Launching the application is easy:

tell application "Filemaker Pro" to activate

Here’s where they went wrong.

2/3: Opening a passworded database is also easy:

tell application "filemaker Pro"
   open "Path:to:database" with password "itsasecret"
end tell

so, putting this altogether you end up with something like:

tell application "System Events"
   set running_apps to name of every application process
   if running_apps contains "Filemaker Pro" then
      --- filemaker is running
   else
      --- it isn't, so restart it
      tell application "Filemaker Pro"
         -- no need to activate it since it will launch as soon as you open a document
         open "Path:to:database 1" with password "itsasecret"
         open "Path:to:database 2" with password "evenmoresecret"
         open "Path:to:database 3" with password "someothersecret"
      end tell
   end if
end tell

One problem you may run into is that when you open a FileMaker database that has a relationship to another database, FileMaker will automatically try to open the related database. If FileMaker tries to open the second database that is also pass protected, you may get the “Enter Password” dialog before the script gets to send the pass directly to FileMaker. It will hang up at this point.

To avoid this, figure out an order in which you can open the databases so that FileMaker does not try to do any of the opening on its own. For instance, if DB1 has a relationship to DB2 and DB3, you could open DB2 and DB3 first, then open DB1. This might get a bit tricky but is the best way to avoid any hang ups.

We set up the following Applescript:


tell application "System Events"
	set running_apps to name of every application process
	if running_apps contains "FileMaker Pro" then
		tell application "FileMaker Pro"
			quit
		end tell
		--- CHECK TO SEE IF FILEMAKER IS RUNNING
	else
		--- IF IT ISNT, RESTART IT
		tell application "FileMaker Pro"
			-- FILEMAKER WILL OPEN WHEN DIRECTED TO OPEN DOCUMENTS
			open "/Applications/FileMaker Pro 6 Folder/Web Security/Security/Web Security.fp5" with password "ultra-secret"
		end tell
	end if
end tell

It sucessfully detected whether FileMaker was running, re-loaded file maker, but failed to open the document. It most likely is a path problem, we found conflicting ways to enter in the path to the document…Any Ideas?

AppleScript gave the following error:

APPLESCRIPT ERROR
FileMaker Pro got an error: The event failed.

Thanks for any possible help!

It seems to definitely be a path issue. You need to direct FileMaker to the absolute path of the file to open, use colons instead of forward slashes and tell it that it is a file it is supposed to open. (“My HD:Applications:FileMaker Pro 6 Folder:Web Security:Security:Web Security.fp5”).

Also, is it necessary to have the “Tell app FileMaker” command inside the “Tell app System Events” command?

This would be my suggestion:



global running_apps

tell application "System Events" 
   set running_apps to name of every application process 
end tell

   if running_apps contains "FileMaker Pro" then 
      tell application "FileMaker Pro" 
         quit 
      end tell 
      --- CHECK TO SEE IF FILEMAKER IS RUNNING 
   else 
      --- IF IT ISNT, RESTART IT 
      tell application "FileMaker Pro" 
         -- FILEMAKER WILL OPEN WHEN DIRECTED TO OPEN DOCUMENTS 
         open file "My HD:Applications:FileMaker Pro 6 Folder:Web Security:Security:Web Security.fp5" with password "ultra-secret" 
      end tell 
   end if 


I don’t know if this is an option for you but to get around the issue of related databases opening. If all the databases have the exact same passwords and groups, the related databases will open without the request for a password.

Aaah! Good call drossi. I did not know this but this will be very useful in the future.

It seems that you are trying to write something to come back up after a crash. I see this question periodically. The big problem is that when FileMaker crashes or is force-quit, your files are left in an inconsistent state, and potentially damaged. To make it even more fun, they may pass the inconsistency check, but have hidden damage that gets progressively worse over time. What you should do is periodically save a Clone of your database (whenever you make file structure changes: layouts, scripts, field definitions, etc, not just changing data), and then do the following to come back from a crash:

  1. Duplicate the clone.
  2. Rename the crashed files and move them elsewhere
  3. Recover the crashed files to get the data out
  4. Put the dupe of the clone as the hosted file
  5. import your data from the recovered file into the new hosted file

Or, you could just live dangerously and bring FM back up after a crash, and hope for the best. If you do that, though, I’d recommend making frequent backups. Remember that you cannot backup a FileMaker database by copying it in the Finder while it is open, as that can also lead to damage. You’d need to script a Save As command from FileMaker.

One way to get around the problem of corrupting the files when you crash is to have FileMaker Server running on a different machine. Then, FM 6/web companion logs into those hosted files. That way, when the web companion machine crashes, the files are not damaged, and you can just relaunch FileMaker to reconnect to the FM Server.