Jump to content

Formatting the Perform AppleScript script step to connect VPN


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

Recommended Posts

XPOST

Our company is switching to VPN for remote users to to connect to our FMS-hosted databases. So I want to incorporate connecting to VPN into our already established procedure for accessing those databases via a FileMaker script.
Our VPN connection is up and running. And I found an AppleScript that works well making and continually checking the VPN connection. But I don't know enough about AppleScripts and how they apply to FileMaker scripts to make it work. From what I could find on the subject, I need to modify the AppleScript steps to work in FileMaker; such as adding a \ in front of each double-quote. But, apparently that's not all.
Here is the raw AppleScript code:
 
on idle
tell application "System Events"
tell current location of network preferences
set myVPN to the service "VPN NAME"
if myVPN is not null then
if current configuration of myVPN is not connected then
connect myVPN
end if
end if
end tell
return 60
end tell
end idle
 
And here's what I did: I created a new FileMaker script and added one step - Perform AppleScript. In the step options, I selected Native AppleScript and entered the above code. (Using Calculated AppleScript didn't appear to be the right choice for this method.) I saved the script and tried running it, but nothing happens. No errors, nothing. From what I was able to find on the subject, I assumed the problem lies with how the AppleScript text is formatted in the script description. But, nothing I tried worked. Can someone show me what needs to be done with the above AppleScript to make it work in a FileMaker script?

One major issue may be the restriction: "Indenting of repeat loops and conditional statements is not supported." This may limit me to stripping the AppleScript down to just the connect VPN portion. But, I really liked what the AppleScript offered in the way of checking regularly to make sure the connection is still active and to re-connect if it isn't. So, if there is another way to do this, I'm all ears.

Finally, just in case there is a better method for all of this that I am just not aware of, here is the "big picture": My remote users each have a small database file they open every day to access our FMS Server-hosted databases. The file contains one button which activates a script that opens the required databases. Switching to VPN simply meant setting up the VPN connection on each computer and changing the External Data Sources in the local database. What I hoped to do is to modify the script so that it first makes the VPN connection and then, once that's completed, opens the databases. An alternative process might be to create a separate script to make the VPN connection and that script could be set up as a Script Trigger which activates when FileMaker is first started up or the file is first opened.

Just to complicate matters, I also need a similar FileMaker script that will connect to VPN on a Windows 8 machine - which, of course, precludes using AppleScript.

Edited by steveald
Link to comment
Share on other sites

You don't need to reformat a working AppleScript in any way when using the 'Native AppleScript' option. You can just paste it as is from the Script Editor application into the "Perform AppleScript" Options window. The only required change is to disable or remove any «tell application "FileMaker Pro"» wrappers you might have.

AFAICT, the real problem with your script is the «on idle» part. I don't think that's ever going to be executed in Filemaker's Perform AppleScript script step, same as it's not going to be executed when running from the Script Editor. You need to save the script as a stay-open application in order for the «on idle» handler to have any meaning. Then you can use another script, called from Filemaker, to launch that application.

Or perhaps you could use Filemaker's native OnTimer script mechanism instead of AppleScript's «on idle».

 

 

Edited by comment
  • Like 1
Link to comment
Share on other sites

Thanks again, comment.

Oddly enough, the AppleScript worked on my home computer but not my work computer (both running current versions of everything) with the on idle steps in place. And putting the AppleScript lines into a Perform AppleScript step set to Native AppleScript did nothing on either machine. The minute I took out the on idle steps, it worked everywhere, but I think I lost the process of checking the VPN connection periodically when I did that. I'll try your suggestion on that count. The AppleScript in it's original context was supposed to be saved as a stay-open application, like you said.

Any thoughts on how to achieve the same goal on a Windows 8 machine? I've heard I might need to use Send Event or VBScript. Should I post that request elsewhere to get the full attention of the Windows experts here?

Link to comment
Share on other sites

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