Sunday, November 22, 2009

Filemaker - Applescript Printer list / faxing a file

In the following artice I will show you two methods that I have created in my solutions.

If you want a list of your installed printers in FileMaker you can use a simple applescript.

I show you two methods. Each of them requires a PrinterList_Global field in your database and on the layout where you execute the script. The script is a simple Perform Applescript command.

The first method uses the print setup utility to get the printer list. You need to have a PrinterList_Global field in your database and on the layout where you execute the script:
----
tell application "Printer Setup Utility"

set allprinters to every printer

set printernames to name of every printer

end tell


set backvalue to ""


repeat with printername in printernames

set backvalue to backvalue & printername & (ASCII Character(13))

end repeat


set cell "PrinterList_Global" of current record to backvalue

---


This can be used to set the default printer on OSX.


2)


The second option uses the lpstat OSX command to get the printer names. This will give you a different list. But the printer names this one gives can be used for the "lp" OSX command. This will be important later when we get to fax sending.


---

set oldDelims to AppleScript's text item delimiters

set PrinterStatusList to {}

try

set cmd to "lpstat -p | grep ^printer"

set PrinterStatus to do shell script cmd as text

set AppleScript's text item delimiters to {" "}

repeat with i from 1 to count of paragraphs of PrinterStatus

set s to paragraph i of PrinterStatus

set p to text item 2 of s as list

copy p to end of PrinterStatusList

end repeat

on error

set PrinterStatus to ""

end try

set AppleScript's text item delimiters to oldDelims


set backvalue to ""


repeat with printername in PrinterStatusList

set backvalue to backvalue & printername & (ASCII Character(13))

end repeat


set cell "PrinterList_Global" of current record to backvalue


--


Okay, now you have the printer list. You can easily create a value list based on this, and let the user choose from it.


What about faxing??


This is where the lp command comes in.

With lp you can send a file (pdf), to a number.


The syntax is the following:


lp -d PrinterNameHere -o phone=PhoneNumberHere filepathandnameHere


You can call this from FileMaker using a do shell script AppleScript Command.


I attached a sample file for printer listing, the faxing is up to you, but based on this, you can easily create it.


You can download the demo file here. (right click - save as).


Be sure to check out: http://crm.fm as well :) Thanx!

The material on this document is offered as is. There is no representation or warranty, expressed or implied, nor does any other contributor to this post. Consequential and incidental damages are expressly excluded. FileMaker Pro is the registered trademark of FileMaker Inc.





5 comments:

  1. Thanks for this wonderful tutorial!

    In my case, I don't want to have the field on my layout. Is there a way to capture the text as some kind of script result and then set the field with another script?

    ReplyDelete
  2. Hi!

    No, you have to write in a field, no script result.
    If you don't want it to appear on the layout, you can change

    set cell "PrinterList_Global" of current record to backvalue
    to
    set field "PrinterList_Global" of table "Table Occurrence" to backvalue

    Then use the other script to work with this.
    If you need further information or help, feel free to drop me a line!

    Regards
    Adam

    ReplyDelete
  3. nice post very well written. i appreciate quality of writing u haveMarkham Developer

    ReplyDelete
  4. nice post very well written. i appreciate quality of writing u havefrases

    ReplyDelete
  5. Nice stuff you got, very interesting to read.
    Well, I do have also in my sleeves, if you have time don't forget to visit
    Houston Electricians

    ReplyDelete