Jump to content
Server Maintenance This Week. ×

Calculated Applescript Syntax


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

Recommended Posts

  • Newbies

Hello, I have this applescript who is working well:

do shell script "curl \"http://127.0.0.1:4490/action.html?macro=4A91C4B8*nome file.jpg\""

Since I should replace “nome file.jpg” with a Filemaker field value, I modified it to be a Calculated Applescript like this:

"do shell script \"curl \"http://127.0.0.1:4490/action.html?macro=4A91C4B8*" & OrderLines::CustomerFileName & "\"\"""

But this script always report me an error about “”” I guess there is some syntax error but I don’t see where. Anyone can help me to understand the logic and correct the syntax?

Link to comment
Share on other sites

You seem to be running into the same issue again and again. Here is a generic method you can use to solve this kind of problem:
 

1. Paste your native, working AppleScript into a text field.

2. Use a calculation field or the Data Viewer to calculate: 

Quote ( Texfield )

This will return, in your example:

"do shell script \"curl \\\"http://127.0.0.1:4490/action.html?macro=4A91C4B8*nome file.jpg\\\"\""

3. Locate the string you want to replace with a field value. Place a closing quote before this string and an opening quote after it and insert a reference to your field in between:

"do shell script \"curl \\\"http://127.0.0.1:4490/action.html?macro=4A91C4B8*" & OrderLines::CustomerFileName & "\\\"\""

 

Another option is to start by replacing any variables that need to use field values with placeholders - for example:

do shell script "curl \"http://127.0.0.1:4490/action.html?macro=4A91C4B8*«fileName»\""

Applying Quote() to the result produces:

"do shell script \"curl \\\"http://127.0.0.1:4490/action.html?macro=4A91C4B8*«fileName»\\\"\""

Now you can make your calculation =

Let (
template = "do shell script \"curl \\\"http://127.0.0.1:4490/action.html?macro=4A91C4B8*«fileName»\\\"\"¶"
;
Substitute ( template ; "«fileName»" ; OrderLines::CustomerFileName )
)

This is especially convenient when you have more than one field value to insert into the AppleScript.

 

In recent versions you can also use the Insert Calculated Result[] script step to populate a variable with the text of the native AppleScript (with placeholders), without having to use the Quote() function. Then you can do just =

Substitute ( $template ; "«fileName»" ; OrderLines::CustomerFileName )

to calculate the final AppleScript.

 

Finally, keep in mind the option to read Filemaker fields directly from the AppleScript.

 

Edited by comment
Link to comment
Share on other sites

This topic is 1365 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.