Jump to content
Server Maintenance This Week. ×

Applescript runs in Editor but not in FM


This topic is 5611 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Here's my applescript:

tell application "FileMaker Pro Advanced"

activate

set theUID to cell "ID" of current record of document "Update Address Book"

end tell

tell application "Address Book"

activate

tell me to open location ("addressbook://" & theUID)

end tell

If I run this applescript in Script Editor it selects the correct person in Address Book. If I put the identical code into a "Perform AppleScript" in a Filemaker Script it selects the Address Book file but then it appears to hang or pause and the Filemaker icon on the dock starts to bounce. Now that is behaviour that suggests that there is a dialogue or message from Filemaker but when I click back on to the database there is no message and the person in Address book never gets selected. If I then run the Script Editor version it immediately selects the correct person in Address Book.

Any ideas why it works in Script Editor but not in Filemaker?

Link to comment
Share on other sites

  • 3 weeks later...

Here's my applescript:

tell application "FileMaker Pro Advanced"

activate

set theUID to cell "ID" of current record of document "Update Address Book"

end tell

tell application "Address Book"

activate

tell me to open location ("addressbook://" & theUID)

end tell

If I run this applescript in Script Editor it selects the correct person in Address Book. If I put the identical code into a "Perform AppleScript" in a Filemaker Script it selects the Address Book file but then it appears to hang or pause and the Filemaker icon on the dock starts to bounce. Now that is behaviour that suggests that there is a dialogue or message from Filemaker but when I click back on to the database there is no message and the person in Address book never gets selected. If I then run the Script Editor version it immediately selects the correct person in Address Book.

Any ideas why it works in Script Editor but not in Filemaker?

Drop the tell in a Filemaker perform applescsript statement:

set theUID to (get data cell "ID" of current record )

open location ("addressbook://" & theUID)

tell application "Address Book" to activate

Edited by Guest
Link to comment
Share on other sites

You said before that it worked in Script Editor, so I assume you mean it fails when you remove the "tell FileMaker"/"end tell" lines. That is to be expected: Script Editor requires those lines but FileMaker requires that you omit them. To get Bruce's script to compile in Script Editor it looks like you'd need to put the first line inside the tell/end tell.

Link to comment
Share on other sites

When you use the "tell me" phrase, it is passed to whoever is running the AppleScript; either Script Editor or FileMaker in this case. The reason you did that is because Address Book (AB) won't do the open location (no error, but it doesn't do it). Script Editor has no problem with open location. So that works. It would also work in Script Editor (without the tell me) if you just moved the open location outside the tell "AB " block.

FileMaker feels the same about open location, no error, but it just doesn't do it. What works in both is to call some other application to do it, the commonest being either Finder or System Events. The following syntax will work in either Script Editor or FileMaker. (You'll need to add your FileMaker field to set the UID, I'm just getting it from AB. Apparently the open location command automatically brings the default app for the URL syntax to the front.)

tell application "Address Book"

	set UID to id of 1st person

end tell



tell application "System Events"

	open location ("addressbook://" & UID)

end tell

You can use similar construction for other commands that FileMaker doesn't like, like: write file

Link to comment
Share on other sites

Fenton that works! Thanks very much.

What I am trying to do is to store the Address Book ID of a person in a field in a Filemaker Pro record. Then the script I was trying to create would jump from the Filemaker Record to the correct record in Address Book. So here's my final code that with your help makes it happen:


tell application "Filemaker Pro"

     set theUID to (get data cell "ID" of current record)

end tell



tell application "System Events"

     open location ("addressbook://" & theUID)

end tell

Thanks again to all.

Link to comment
Share on other sites

This is actually the politically correct syntax. I've commented out the tell FileMaker lines. Then, if you ever need to copy/paste into Script Editor, you can just remove the comments.

You can leave yours as is, but some FileMaker AppleScript experts (Jimmy Jones) say you should not have tell "FileMaker" lines unless absolutely necessary (as when nested into another app's tell block; but that is rare).


--tell application "Filemaker Pro"

     set theUID to (get data cell "ID" of current record)

--end tell



tell application "System Events"

     open location ("addressbook://" & theUID)

end tell

Link to comment
Share on other sites

This topic is 5611 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.