Applescript Objective C不输出变量

时间:2018-05-06 10:51:00

标签: xcode applescript

使用Xcode,我试图管道我用来检查打印服务器上可用打印机列表的shell命令的输出。它在终端中工作,但输出只能在调试器中看到,当我将脚本放入脚本编辑器时,我将输出显示为"语法错误"。

我试图通过显示警报命令将其显示为警报,但我没有运气。

on Button_(sender)
set Printerlookup to  "/usr/local/bin/iprntcmd --listprintersonserver printerserver.com"
set Printers to do shell script Printerlookup
display alert "The available printers are:" & Printers
end Button_

编辑:

这是整个appdelegate。

script AppDelegate
property parent : class "NSObject"
property txtBox: ""
-- IBOutlets
property theWindow : missing value

on applicationWillFinishLaunching_(aNotification)
    -- Insert code here to initialize your application before any files are opened 
end applicationWillFinishLaunching_

on applicationShouldTerminate_(sender)
    -- Insert code here to do any housekeeping before your application quits 
    return current application's NSTerminateNow
end applicationShouldTerminate_
use scripting additions
on Button_(sender)
if txtBox is "" then
    display alert "Please enter some text"
    else
set iPrntlookup to  "/usr/local/bin/iprntcmd --listprintersonserver "& txtBox &"printerserver.com"
set Printers to do shell script Printerlookup
display alert "The available printers are:" & Printers as text
    end if

end Button_
end script

这是预期的输出,可以在调试器区域找到,而不是对话框。

2018-05-07 21:34:12.925412+1000 iPrint Local[29523:430596] MessageTracer: 
Falling back to default whitelist
2018-05-07 21:34:17.104407+1000 iPrint Local[29523:430596] *** -[AppDelegate 
Button:]: iprntcmd v06.07.01
Listing printers on testprintserver.com.
ipp://testprintserver.com/ipp/printer1
ipp://testprintserver.com/ipp/printer2 (error 1)

1 个答案:

答案 0 :(得分:0)

在脚本顶部添加use scripting additions语句。