我在Xcode中有以下AppDelegate.applescript。我创建了一个接口来使用它,脚本(和UI)中的所有代码都可以正常工作。但请注意UI底部的服务器版本(下面的链接中的图像)。现在这是硬编码的。
我想让它变得动态,阅读httpd -v |grep version
的输出,这可能类似于Server version: Apache/2.4.18 (Unix)
。
换句话说,我希望能够do shell script "/usr/local/bin/httpd -v |grep version"
并在UI中的某种文本单元格(或其他单元格)中显示结果。如果让它更容易,我可以提供项目。提前谢谢!
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 :(得分:0)
正如vadian提到的那样链接文本域和:
property httpdVersion : missing value
httpdVersion's setStringValue_(do shell script "/usr/local/bin/httpd -v | grep version")