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

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

Recommended Posts

Posted

FMP 11 client running on Mac OSX 10.6

FMP 11 Server running on MS WIndows Server 2003

I use the old but functional joinPDF command line tool from <http://download.cnet.com/joinPDF/3000-18483_4-36691.html> to automate the joining of multiple PDFs into a single file. The specific script step is:

Perform AppleScript [tell application "System Events" do shell script "joinPDF/Users/Shared/FMP/mailing.pdf /Users/Shared/FMP/subrecipient-*.pdf" end tell]

The command joinPDF/Users/Shared/FMP/mailing.pdf/Users/Shared/FMP/subrecipient-*.pdf works perfectly when entered directly into Terminal but fails as a FMP Perform AppleScript step with two error messages:

System Events got an error: JavaVM: Failed to load JVM: /System/Library/Frameworks/JavaVM.framework/Versions/1.6//libserver.dylib

JavaVM: Failed to load JVM: /System/Library/Frameworks/JavaVM.framework/Versions/1.6//libserver.dylib

and

This action cannot be performed because this file is not modifiable.

Everything was fine until I updated Java to take care of the recent fuss over FlashBack, and as I said there's absolutely no problem with the exact same joinPDF command when entered directly in Terminal. It's just when run as an AppleScript System Events command that it fails. I've never seen a command line command work in Terminal but fail in a "AppleScript System Events do shell script" but it's definitely happening here. Also, despite the "This action cannot be performed because this file is not modifiable" error message the folder where the PDFs are located is read/write for Everybody.

Can anybody help me figure out why the Java update broke FMP's ability to call the joinPDF command? Alternatively, are there any alternative methods to script the joining of PDFs where you do not know in advance the file names or the number of PDFs involved?

Thanks.

Colin

Posted

What user is the command run as when triggered by the AppleScript? If you can run it from the command line, but not from FileMaker, my guess is it's run as a different user.

My second guess would be the environment it's run in, perhaps your terminal environment set's a variable like JAVA_HOME, for example, but that same variable does not exist when called via the AppleScript.

Alternatives:

ScriptMaster plug-in could probably do it. Search that forum for PDF and see what you can find for customized functions.

Posted

The script is being run with full access privileges by the same user via Terminal as well as through the FMP script. Also, the folder which contains the PDFs and to which the joined PDF is saved has read/write privileges for everybody. You might be correct regarding Terminal setting an environment variable which isn't being set via the AppleScript, after all something must be different between between the two methods of running the command. I'll look into ScriptMaster as a work-around if I cannot solve the AppleScript error - thank you for the suggestion.

I wasn't aware I could run a shell command directly from within a FMP script without calling System Events via AppleScript. Can you direct me where I can get more information on this technique?

Thanks.

Posted

I wasn't aware I could run a shell command directly from within a FMP script without calling System Events via AppleScript. Can you direct me where I can get more information on this technique?

Not really, because it's not a technique - it's something that was always a part of AppleScript.

Also, you should test your scripts using the AppleScript Editor rather than the Terminal. Filemaker runs its AppleScripts practically the same way the Editor app does.

Posted

I don't know much about AppleScript, but here is a snippet of a my working AppleScript, it might help you to figure out how to call a shell command directly.


tell application "Terminal"

do script "/scripts/ChownChmodAll.sh " & param & "; exit"

end tell

Posted

Following on from your recommendations I ran

do shell script "joinPDF /Users/Shared/FMP/mailing.pdf /Users/Shared/FMP/subrecipient*.pdf"

within the AppleScript Editor and was successful, but the exact same command called via a script step in FMP

Perform AppleScript ["do shell script "joinPDF /Users/Shared/FMP/mailing.pdf /Users/Shared/FMP/subrecipient*.pdf""]

failed with the same Java error I received with my earlier tell application "System Events script.

Then I tried AppleScript Editor with

tell
application
"Terminal"

activate

do script
"joinPDF /Users/Shared/FMP/mailing.pdf /Users/Shared/FMP/subrecipient-*.pdf"

end
tell

which was successful, but running it as a FMP script step

Perform AppleScript ["tell
application
"Terminal" activate do script "joinPDF /Users/Shared/FMP/mailing.pdf /Users/Shared/FMP/subrecipient-*.pdf" end tell"]

failed with the familiar Java error.

I then discovered that if I opened Terminal from Finder or a command in Apple Script Editor everything is OK, but if Terminal is opened from an AppleScript called by FMP I can't run any Java. Even just typing "java" gets me an error in Terminal if it's opened from FMP. So dansmith65 is correct - the Terminal environment is different when called by FMP compared to when opened in Finder or directly from AppleScript. So, does anybody know how to enable Java in a Terminal session when called by FMP?

Posted

I don't know - I have never encountered any issues running a script tested in AppleScript Editor inside Filemaker. I cannot reproduce your problem because I don't have the joinPDF library. Why don't you try a more native method, such as:

http://macscripter.net/viewtopic.php?pid=148281#p148281

Posted

I like the GhostScript solution and will give it a try. Assuming it works it's certainly more elegant than my joinPDF command as it doesn't require third party software.

Incidentally, here's how to reproduce the java problem on any Mac running OS X 10.6.8 with the recent Java security updates:

Run in AppleScript Editor:

Tell application "Terminal"

do script "java"

end tell

Result: success

Run the same script as a FMP script step (don't forget to first quit Terminal):

Perform AppleScript ["tell application "Terminal" do script "java" end tell"]

Result: error

This was not an issue prior to Java for Mac OS X 10.6 Update 7.

Posted

I'm not sure about Mac's, but on Linux there are a few preferences files that are parsed when a user logs in: ~/.bashrc and/or ~/.bash_profile

In Linux, when running a cron command, if you want these files parsed, you specifically need to call them. I'm assuming that's the basic problem you are having with FileMaker, I just don't know how that same concept translates to Mac.

In a terminal try this:


ls -la ~

Do you see a file called .bashrc or .bash_profile?

Posted

I see a file called .bash_history and another called .profile, but nothing called .bashrc or .bash_profile.

Incidentally, I tried the GhostScript solution suggested by hanzel and while it joins the PDFs into a single file, the result is not quite the same as a regular PDF and SuperContainer can't create a thumbnail for it for some reason so this solution will not work. As a workaround I've configured Terminal to run as a startup item (run in the background then hidden by Dock Dodger) so my Java command joinPDF now works once more when called by an FMP script. It's not elegant but Terminal has a small footprint and the few users who need this script would never need to run Terminal for any other purpose. I even tried using AppleScript to instruct Finder to open Terminal rather than opening Terminal with a single AppleSCript command but it still opens in a non-Java compliant mode. Basically any method I use to automate the opening of Terminal from within FMP results in it being unable to run any Java commands.

I'm going to try finding a solution with ScriptMaster tomorrow. Frankly, this appears to me to be a bug with either FMP or Java. Surely Terminal should behave the same way whether opened by AppleScript Editor or by an AppleScript run by FMP?

Posted

Here's another option using a python script installed on os x used by Automator.

http://blog.gotofritz.net/howto/joining-pdf-files-in-os-x-from-the-command-line/

Posted

you might be able to get it working by adding a line to your applescript:


tell application "Terminal"

        activate

        do script ~/.profile

        do script "joinPDF /Users/Shared/FMP/mailing.pdf /Users/Shared/FMP/subrecipient-*.pdf"

end tell

Again, I'm kinda taking a stab in the dark here by relating to how this would work with Linux, but Mac is a different animal so it may or may not work. Regardless, I don't see any way the above script could do any harm to your system (open up that .profile file to see what's in it if you want to be sure).

Posted

hanzel's python approach worked, although even it wasn't completely straightforward. The command

"/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py" -o /Users/Shared/FMP/mailing.pdf /Users/Shared/FMP/subrecipient-*.pdf

worked perfectly in Terminal but AppleScript tripped on the spaces in Combine PDF Pages.action with "Expected end of line, etc. but found identifier." error. Changing it to Combine\ PDF\ Pages.action just changed the error to "Expected end of line, etc. but found unknown token."

Rather than struggle with getting AppleScript to parse the path to the python script I simply made a copy of join.py in another folder and ran it in a shell script from there. Result: success, and no need to mess around with Terminal.

Figuring I was on a roll I next tried dansmith65's suggestion just to see if it would work, but trying to run ~/.profile gets a Permission denied error. I tried sudo ~/.profile but that gives command not found. I ran a cat of ~/.profile but that only gave some entries related to MacPorts and nothing which appears to help the Java environment.

At this point I'm more than happy to use the Python solution. It works even better than my old joinPDF Java command as it doesn't require any software installation on the client Macs and all I have to do is place a copy of join.py in a defined location. Still, I can see this being an issue if anybody wants to script a Java shell command, and I was able to reproduce the problem in FMP 12 so it's not going away.

In any case, thank you everybody for helping me with this. I've learned more information on shell scripting and used Python for the first time.

Posted

At this point I'm more than happy to use the Python solution. It works even better than my old joinPDF Java command as it doesn't require any software installation on the client Macs

Indeed - and that is what I suggested in post #8 above, including the correct path to the existing script (at least one that works for me).

Another thing that's worth pointing out: if a PDF is generated by Filemaker, you can append it to an existing PDF file directly, without needing any post-processing.

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