Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

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

Recommended Posts

Posted

I can't figure how the "do shell script" works on OS X 10.5.6. It seems it handles spaces/escaping characters differently than e.g. Terminal.

In terminal I can run:

open /Users/davidwikstrom/Desktop/fold der/test.txt

If I use ScriptMaster, this fails, as does the same thing if I don't even try escaping but just leave the space in there. Single or double quotation marks around the path don't help either.

I can of course run:

open /Users/davidwikstrom/Desktop/folder/test.txt

succesfully in both Terminal and ScriptMaster.

This is the last piece in replacing Troi File by ScriptMaster in an existing cross-platform solution. The aim is really simple, just to open a file or folder (without knowing whether the path is for a file or a folder). On Windows Open URL does the trick, and I was hoping to be able to use ScriptMaster to replicate Troi File's "launch" on the Mac.

I'm sure I'm missing something obvious, and you guys will tell me what right away...

Posted

Sam Barnum very generously got me on the right track (via e-mail) - sending each part as a separate argument.

The code I use to open a file or folder (this is for Mac only) is:

String[] cmd = ["open", filePath];

Process process = Runtime.getRuntime().exec(cmd);

String processResult = process.getInputStream().getText();

process.waitFor();

exitValue = process.exitValue();

return processResult;

Since I use this only for opening, I just set the filePath variable, but you can of course imagine setting open as a variable as well.

Posted

While I think it's great that you can use ScriptMaster for this, and I'd like to learn it better (I find Java intimidating). I would submit that it's a lot easier on a Mac to just use AppleScript, which can be used in a FileMaker Perform AppleScript step, either as a calculation (where there's a lot of escaping to do), or as native AppleScript written as text (or copy/pasted from Script Editor). AppleScript can also call shell scripts, via: do shell script "cmd" (where you have to escape spaces, but it's fairly easy; or you can set paths into an AppleScript variable safe to use, with the phrase, quoted form of "path with spaces", or really any text.

Posted (edited)

I find AppleScript almost as, or even more, intimidating than java.... :

Actually, I just didn't think of calling a shell script with AppleScript - just opening the file/folder which I believe would require specifying the app to open with (?) and differentiating between files and folders... Since I'm using ScriptManager anyway, I think it's kind of neat to be able to call this function as it it was just a normal FileMaker function - otherwise you're perfectly right that it would be more logical to just use the AppleScript and not use non-FileMaker stuff when you don't have to.

Edited by Guest
  • 2 years later...
Posted

While I think it's great that you can use ScriptMaster for this, and I'd like to learn it better (I find Java intimidating). I would submit that it's a lot easier on a Mac to just use AppleScript, which can be used in a FileMaker Perform AppleScript step, either as a calculation (where there's a lot of escaping to do), or as native AppleScript written as text (or copy/pasted from Script Editor). AppleScript can also call shell scripts, via: do shell script "cmd" (where you have to escape spaces, but it's fairly easy; or you can set paths into an AppleScript variable safe to use, with the phrase, quoted form of "path with spaces", or really any text.

I love AppleScript, and have done a lot of work from FileMaker using it. However, there are downsides to using AppleScript, including: 1) returning a value requires hard-coding a field/layout/table name into the AppleScript code; and 2) if you are running more than one copy of FileMaker at a time, it can have errors. I have written custom AppleScript handlers to getFromFMP and sendToFMP that address both of those issues, but they still require having a special "AppleScript Data Transfer" layout with a global field on it. Running a shell script directly in a command that returns a value into a variable is much more concise, and less likely to break if you rename a field or layout or table.

As you point out, though, the "quoted form of [somepath]" that AppleScript offers is extremely useful.

Posted

I love AppleScript, and have done a lot of work from FileMaker using it. However, there are downsides to using AppleScript, including: 1) returning a value requires hard-coding a field/layout/table name into the AppleScript code;

The simplest way to avoid this to write the result to a global field then use FileMaker scripting to handle the result.

Globals do not need to be present on the layout. You do need a valid table occurrence name ( NOT base table name) and global field name but the TO does not need to be attached to a layout.

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