I didn’t know anything about AppleScript, but I was able to find enough info here and in Apple’s documentation to write a couple of very simple scripts (saved as applications). One opens FM Pro 8.5 and is supposed to open a specific database that’s shared among 5 people; one closes FM Pro. I’m using cron to schedule the open script in the morning and the close script at night.
The problem is that the open script only partially works, so FM Pro opens, but the database doesn’t (I get an error message). The script compiles fine, but maybe my syntax needs adjustment. Then again, I’m wondering if it’s related to the script being run on OS X Server (10.3.9). Here’s why I’m really puzzled: If I double click the script, everything works just fine and the database opens. I also tested a script to do the same thing with a dummy FM DB on my work computer (Intel iMac running 10.4.9, AppleScript 1.10.7) and everything worked ok.
Here’s the script:
tell application "FileMaker Pro"
open file "Server_Partition1:Folder1:Folder2:FM_db.fp7"
Any ideas are appreciated.
Model: G4 Mac Tower
Operating System: Mac OS X (10.3.9)
I know the syntax for opening a FileMaker database from a FileMaker Server is:
tell application "FileMaker Pro"
But I’m not sure if this is applicable to your situation or not. Applescripts for remote-running FileMaker databases can be a bit odd, not all the features work the same (or at all).
Thanks for the attempt, but we’re not running FileMaker Server (although the DB is on a server). Really all I need to happen is for the copy of FileMaker running on the server to start up and open the DB in the morning and then quit at night before the backup starts. Users are accessing the DB remotely when it’s running.
The scripts are on the server, so it’s really a local problem rather than a remote one. The error I get every morning is “AppleEvent timed out.” Again, FileMaker is running, but the DB is not open.
I don’t know much about this, as I’m in the process of learning, myself.
However… I don’t know if you have read much about timeout errors. You can set the timeout time to be longer/shorter than the default (120 seconds) using the following code:
with timeout of 5 seconds
This can either wrap around the command, or come after it (for the most part).
On the other hand, I would assume that a timeout error is occurring in this case because it’s trying to load something and can’t find it, or there is an unanticipated dialog box that is not being handled.
Run the script and watch for these errors to come closer to your solution.
Yes, I had considered that the error was due to some delay in opening the DB, but it evidently only happens when the script is activated by cron.
But if there is a dialog box that pops up when the script runs automatically, then that certainly could be the problem. I will have to set the script to run when I’m watching.
If you run your script as a script (not an applet) you can watch what it’s doing step by step in the “event log” tab at the bottom of the Script Editor window. This will also show you how far it got before it errored out. Now, the event log doesn’t show everything that the script does, only the actions that require getting information. Usually it covers enough for trouble-shooting.
If that’s not enough, look into creating a log file and logging bits of information along the way. I’m also interested in finding a way to access a remote FMP database and will be getting into this more tomorrow.
For now, here’s a jump start for logging info into a log file:
tell someApp "AppName"
set logFilePath to (filePath & "scriptLog.log")
set fullMessage to return & myMessage
set fileID to open for access file logFilePath with write permission
write fullMessage to fileID starting at eof
close access fileID
I found that very helpful in my last complex script project.
Only thing I can think that’d cause the error on some systems and not others (cron launches an applescript application is the same as double-clicking, yes?) is minor details in the syntax:
open database “Server_Partition1:Folder1:Folder2:FM_db.fp7”
open file “Server_Partition1:Folder1:Folder2:FM_db.fp7”
All my scripts use the first syntax, and don’t specify a file from the string - but then, that’s running OS 8.6 on FM4.1 so YMMV with a more, ah, current version of things. I’m about five months away from setting up FM9 on a new system.
I’ve also found FileMaker enjoys the ‘launch’ or ‘activate’ command more than just being told what to do before it’s running:
tell application “FileMaker Pro”
activate --or launch
The last thing I can think of to explain why the script works when a user (you) launches the script from the Finder and doesn’t work when cron launches the script is that the file path to the database file might appear different to different users - doesn’t make much sense, but a script that tests for file exists run by a user works and then run by cron doesn’t then that’d tell you the database file path needs to be reworked for cron.
Glad you mentioned that Pandrake,
I just caught wind that opening a FMP database at it’s original location through Finder may cause it to become corrupt. So, at all costs, avoid that.
Open it through a FMP tell block.