Jump to content
Sign in to follow this  
wintergreen

get result from calculated applescript

Recommended Posts

Is there a simple way to return the result of a "calculated applescript" script step to the originating script?

I appreciate this can be done by having the applescript itself write the result into a field on a layout, but i was hoping for something a bit more elegant

Share this post


Link to post
Share on other sites

No, you've got to write it to a field. You do not have to be on the layout, if you specify the layout or table occurrence* name. It is easiest to do so with global fields, which do not care about "current record".

*AppleScript uses the term "table", but it always means a FileMaker table occurrence (what you see on the relationship graph). Nothing can see the FileMaker "tables", which are better called "base tables", just to avoid confusion.

Here's a funny little file I created to test various ways to set a field.

[ Fixed database name in AppleScript. Oops! Never make cosmetic last-minute changes :-]

AS_Tests2.zip

Edited by Guest
Fixed database name in AppleScript

Share this post


Link to post
Share on other sites

thanks that's really useful...

A point for anyone else who's using this:

The applescript refers to database "AStest"; this should be "AStests"

Share this post


Link to post
Share on other sites

Oops! Last minute changes, as "ATests" seemed a better name for the file. Duh. Fixed it in the download file of my 1st post.

Share this post


Link to post
Share on other sites

Ok, this bit of code appended to the end of any fm applescript will capture the result:

--applecript goes here

set the_result to result

set the_result to my asUnicodeString(the_result)

set the_database to "my database" --change this to the database to write to

set the_table to "my table" --change this to the table occurence to write to

set the_field to "my field" --change this to the table occurence to write to

tell me

set field the_field of table the_table of database the_database to the_result

end tell

--from http://discussions.apple.com/thread.jspa?threadID=1105795

on asUnicodeString(a)

local astid, NIL

set astid to a reference to AppleScript's text item delimiters

set NIL to "" as Unicode text

try

{«class AAAA»:a}'s «class BBBB»

on error t -- t = "Can't get «class BBBB» of {«class AAAA»:a}"

try

set astid's contents to {"{«class AAAA»:"}

set t to NIL & t's text items 2 thru -1

set astid's contents to {"}"}

set t to NIL & t's text items 1 thru -2

set astid's contents to {""}

return t -- t = a, which is in Unicode text

on error errs number errn

set astid's contents to {""}

error errs number errn

end try

end try

end asUnicodeString

Edited by Guest

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×

Important Information

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