创建一个AppleScript添加打印机 [英] Create an AppleScript to add printers

查看:916
本文介绍了创建一个AppleScript添加打印机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜查了互联网的各个角落,包括我的连接,但没有人很了解的AppleScript中的按键事件。

我试图做到的是,首先要求变量添加打印机,如IP地址的打印机的位置,然后该脚本将打开添加打印机应用程序,它存在于所有Mac和脚本,然后将使用模拟按键输入所有的previously设置变量到字段,然后单击添加,这样它添加打印机。

它应该是这个样子:

设置IP_ADDRESS为文本返回(显示对话框输入打印机IP地址​​默认回答按钮{OK}的默认按钮1)集PRINTER_NAME以文本返回的(显示对话框中的输入打印机名称默认回答按钮{OK}默认按钮1)集printer_location以文本返回的(显示对话框输入打印机的位置默认回答按钮{OK}默认为1按钮)告诉应用程序添加打印机来激活告诉应用程序系统事件    告诉进程添加打印机        告诉窗口1 - 或窗口1            单击工具栏按钮1IP - 或键3            告诉1组2组组合框2                按键IP_ADDRESS            告诉结束            延迟1            告诉组1组1                文本字段1的设定值PRINTER_NAME                文本字段2的设定值printer_location                 - 你不能用保留字位置            告诉结束        告诉结束    告诉结束告诉结束


解决方案

如果您替换所有告诉应用程序系统事件

阻止

做shell脚本-p使用lpadmin与& ¬
    引述PRINTER_NAME和放大器形式; ¬
    -L&放大器;引述printer_location和放大器形式; ¬
    -E -v&放大器;援引形式(LPD://&放大器; IP_ADDRESS)及¬
    -P&放大器; \"/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/PrintCore.framework/Versions/A/Resources/Generic.ppd\"

在小牛它应该工作。

I have searched all corners of the internet, including my connections, yet nobody knows much about keystroke events in AppleScript.

What I'm trying to accomplish is an AppleScript that adds printers by first asking for the variables such as the IP address an the location of the printer, then the script will open up the AddPrinter application that exists on all Macs and the script will then use simulated keystrokes to input all the previously set variables into the fields and click "Add" so that it adds the printer.

It should look something like this:

set ip_address to text returned of (display dialog "Enter Printer Ip Adress" default answer "" buttons {"OK"} default button 1)

set printer_name to text returned of (display dialog "Enter Name of Printer" default answer "" buttons {"OK"} default button 1)

set printer_location to text returned of (display dialog "Enter Location of Printer" default answer "" buttons {"OK"} default button 1)

tell application "AddPrinter" to activate

tell application "System Events"

    tell process "AddPrinter"

        tell window 1 -- or "window 1"

            click button "IP" of toolbar 1 -- or "button 3"

            tell combo box 2 of group 2 of group 1

                keystroke ip_address

            end tell

            delay 1

            tell group 1 of group 1

                set value of text field 1 to printer_name

                set value of text field 2 to printer_location

                -- you can't use the reserved word "location"

            end tell

        end tell

    end tell

end tell

解决方案

If you replace all the tell application "System Events" block with

do shell script "lpadmin -p " & ¬
    quoted form of printer_name & ¬
    " -L " & quoted form of printer_location & ¬
    " -E -v " & quoted form of ("lpd://" & ip_address) & ¬
    " -P " & "/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/PrintCore.framework/Versions/A/Resources/Generic.ppd"

under Mavericks it should work.

这篇关于创建一个AppleScript添加打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆