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
+1,但'* .ppd'路径可能应该是'/ System/Library/Frameworks/ApplicationServices.framework/Frameworks/PrintCore.framework/Resources/Generic.ppd',以避免引用特定的框架版本'A')。 – mklement0
是的,你是对的。 –
是的,但我怎样才能使一个applescript做上述使用设置变量 –