2014-03-27 49 views
2

我搜索了互聯網的所有角落,包括我的連接,但沒有人知道AppleScript中的按鍵事件。創建一個AppleScript來添加打印機

我想要完成的是一個AppleScript,它通過首先詢問變量(如IP地址和打印機位置)來添加打印機,然後該腳本將打開所有Mac上存在的AddPrinter應用程序,以及腳本將使用模擬擊鍵將所有先前設置的變量輸入到字段中,然後單擊「添加」,以便添加打印機。

它應該是這個樣子:

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 

回答

3

如果用

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" 
下小牛它應該工作

全部更換tell application "System Events"塊。

+1

+1,但'* .ppd'路徑可能應該是'/ System/Library/Frameworks/ApplicationServices.framework/Frameworks/PrintCore.framework/Resources/Generic.ppd',以避免引用特定的框架版本'A')。 – mklement0

+0

是的,你是對的。 –

+0

是的,但我怎樣才能使一個applescript做上述使用設置變量 –

相關問題