2016-07-05 49 views
0

我在Xcode中有以下AppDelegate.applescript。我创建了一个接口,并且脚本中的所有代码(以及UI)都可以正常工作。但请注意UI底部的服务器版本(下图链接中的图片)。现在,这是硬编码。AppleScript + Xcode - 从cli输出读取var并插入文本字段

我想让它变成动态的,读取httpd -v |grep version的输出,可以是类似于Server version: Apache/2.4.18 (Unix)的输出。

换句话说,我希望能够do shell script "/usr/local/bin/httpd -v |grep version"并在UI中的某种文本单元格(或其他单元格)中显示结果。如果更容易,我可以提供该项目。提前致谢!

UI of the App

script AppDelegate 

#### PROPERTY LIST #### 
    property parent : class "NSObject" 
    property startApache : missing value 
    property restartApache : missing value 
    property stopApache : missing value 
    property editConfig : missing value 
    property editVHosts : missing value 
    property openDir : missing value 
    property resetConfig : missing value 

#### APACHE CMDs #### 
    on startApache_(sender) 
     do shell script "/usr/local/bin/apachectl start" with administrator privileges 
    end startApache_ 

    on restartApache_(sender) 
     do shell script "/usr/local/bin/apachectl restart" with administrator privileges 
    end restartApache_ 

    on stopApache_(sender) 
     do shell script "/usr/local/bin/apachectl stop" with administrator privileges 
    end stopApache_ 

    on editConfig_(sender) 
     do shell script "open -a /Applications/BBEdit.app /usr/local/etc/apache2/2.4/httpd.conf" 
    end editConfig_ 

    on editVHosts_(sender) 
     do shell script "open -a /Applications/BBEdit.app /usr/local/etc/apache2/2.4/extra/httpd-vhosts.conf" 
    end editVHosts_ 

    on openDir_(sender) 
     do shell script "open /usr/local/var/www/htdocs/" 
    end openDir_ 

    on resetConfig_(sender) 
     display dialog "Are you sure you want to reset the httpd.conf to it's default settings?\n\n This cannot be undone!" with icon stop with title "Reset Configuration File" 
     do shell script "/usr/sbin/apachectl stop" with administrator privileges 
     do shell script "cp /usr/local/etc/apache2/2.4/httpd.conf.default /usr/local/etc/apache2/2.4/httpd.conf ; cp /usr/local/etc/apache2/2.4/extra/httpd-vhosts.conf.default /usr/local/etc/apache2/2.4/extra/httpd-vhosts.conf" with administrator privileges 
    end resetConfig_ 


    on applicationWillFinishLaunching_(aNotification) 
    end applicationWillFinishLaunching_ 

    on applicationShouldTerminateAfterLastWindowClosed_(sender) 
     return true 
    end applicationShouldTerminateAfterLastWindowClosed_ 

    on applicationShouldTerminate_(sender) 
     return current application's NSTerminateNow 
    end applicationShouldTerminate_ 

end script 
+0

分配结果的'做外壳script'线给一个变量,文本字段连接到该属性脚本并将其'stringValue'设置为变量。 – vadian

+0

我不知道我在做什么错。甚至没有:将我的​​Outlet设置为“这是一些文本”正在工作。 –

+0

设置httpdVersion的stringValue()为“这是一些文本”\也不起作用 –

回答

0

由于vadian提到的链接文本字段及:

property httpdVersion : missing value 

httpdVersion's setStringValue_(do shell script "/usr/local/bin/httpd -v | grep version") 
相关问题