Storing the AppleScript in a blob field has a major advantage: you don’t have to worry about whether or not the script is present on the client machine in the correct directory. The disadvantage is that if the script is large and you use it a lot, saving the script every time adds a lot overhead.
Let’s run an AppleScript that runs a shell command that returns the contents of the current working directory.
//Returns the name of the operating system
var osname = application.getOSName();
Then run an AppleScript or the equivalent VBScript depending on what platform is returned.
Someone else will have to do the “HOW TO” for windows (and linux). I can’t imagine it being much different though – maybe just change out “osascript” with the VBScript equivalent when calling application.executeProgram().
david:
1)
Summary: don’t blow your machine up with all this power.
david
Too late.
But I can’t make the procedure work with other apps. I tried to open an image using Preview, but I get a “cannot execute” error…
Have you tried with apps other than applescript, by any chance?
Riccardino:
But I can’t make the procedure work with other apps. I tried to open an image using Preview, but I get a “cannot execute” error…
Have you tried with apps other than applescript, by any chance?
In OS X terminal, this command opens a pdf in Preview:
open -a preview /Users/admin/Desktop/93260403.pdf
The parameters for executeProgram would look like this then:
Combine this with the applescript from the first post, you could return a list of all the jpg files in a directory and then open them in preview. All without leaving Servoy.
Riccardino:
But I can’t make the procedure work with other apps. I tried to open an image using Preview, but I get a “cannot execute” error…
Have you tried with apps other than applescript, by any chance?
In OS X terminal, this command opens a pdf in Preview:
open -a preview /Users/admin/Desktop/93260403.pdf
The parameters for executeProgram would look like this then:
Combine this with the applescript from the first post, you could return a list of all the jpg files in a directory and then open them in preview. All without leaving Servoy.
david
I tried and it works. Thanks
But, I’m just curios, why do we have to use a shell command to open an application? Isn’t it possible to call directly an app and make it launch the file, as the sample in method editor shows for Windows environment?
Riccardino:
But, I’m just curios, why do we have to use a shell command to open an application? Isn’t it possible to call directly an app and make it launch the file, as the sample in method editor shows for Windows environment?
My assumption about application.executeProgram() is that it doesn’t open a program directly but passes the command string on to the operating system “console” which does the actual execution.
The example given works for windows because that’s the correct command string for the windows console.
For OS X, the operating system “console” is the default shell which you normally access with the terminal app. Hence, the sample in the method editor – no matter how you format the paths – will not work on OS X because that’s not how you specify opening a file using the OS X default shell.
If my guesses are correct, the windows example and my example are the same thing. If I’m not correct…hey, at least it works!
You don’t have to store an applescript as a file in order to run it from Servoy – you can type the applescript string into a Servoy method directly (use the osascript shell command format):
application.executeProgram(‘osascript’,‘-e’,‘tell application “Finder” to say “David”’);
Which gives you the ability to use Servoy field data to build your applescript string:
application.executeProgram(‘osascript’,‘-e’,‘tell application “Finder” to say "’ + contactname + ‘"’);
I’ve kept this example simple to get my point across. I hope that it is obvious that you can do a LOT with this – up to and including building an entire AppleScript “wizard” in Servoy a la the SQL wizard that is included in the CRM example solution.
HJK:
Do you know a vbscript, which does this?? or a workaround? Im trying to launch files (not programs!) within Servoy on Windows. I can’t get right!
I was afraid you would ask this question HJK…
For starters, you already know that the example for application.executeProgram() doesn’t work as the example indicates. You need to have forward slashes in the paths instead of back slashes:
application.executeProgram(‘C:/path to excel program’, ‘C:/path to excel file’); //this works
This approach has it’s problems in that you have to specify a path to the program. This post discusses in detail:
Now, here is where I reach my limitations. I don’t know how to open a file using VBScript. But I can’t imagine it being a big deal if you know VBScript – unless it is a big deal because they kept file management out of VBScript since it was primarily intended as a client-side scripting language for the web. However, I think there are extensions or something to get around this limitation but I may be dead wrong.
Here’s the next best thing – how to run a VBScript using application.executeProgram():
open note pad – type "wscript.echo “hello dude” – save as “hello.vbs”
run cmd – navigate to the directory you saved hello.vbs – type in “cscript hello.vbs” – as you might expect, it returns “hello dude.”
in Servoy, create a method with this line: "field_name = application.executeProgram(‘cscript’,‘C:/path to file/hello.vbs’); – create a button to run it and put the field “field_name” on a form, and “hello dude” is returned to the field.
Somebody else will need to take it from here. I’m would think that you could utilize a number of different scripting languages in this fashion (replace out ‘cscript’ with equivalent command to run a perl script for example? – just guessing here). All I can confirm is that you can run .vbs files this way so whatever you can put in one of them is going to work from Servoy.
I’d be interested in the VBScript to open a file myself if someone could post it.
Its very strange. from the 10 times that I doubleclick the script is started once.
the other times I’ll get runtime error.
(if I start with cscript test.vbs //x : debugger mode)
virusscanner is not the issue. (is off!)
Here is the code for Windows to start/launch a file with the associated program.
The vbscript does not allways run, because of security issues (virusscanner etc..)