我创建了一个启动停止系统守护进程的应用程序。我还在项目中创建了一个首选项Window
,并链接到Preferences (⌘,)
菜单项。在这个首选项窗口中,我有一些Text Field
框,如Apache Path,MySQL Path等。
我想“链接”这些框到应用程序的Info.plist(或强制应用程序在Application Support中创建自己的plist)。每当编辑它们并且用户单击“确定”时,也应该写入plist。
我还需要从plist中读取这些applicationWillFinishLaunching
,以便在应用启动时填充
我尝试了很多不同的方法,但都没有效果。 plist永远不会被写或读。
答案 0 :(得分:0)
解决!感谢MacScripter的工作人员,他们摇滚!方法如下:
property configOK : missing value property apacheLocation : "" property pathApache : missing value
关于applicationWillFinishLaunching_(aNotification)
tell standardUserDefaults() of current application's NSUserDefaults registerDefaults_({apacheLocation:apacheLocation}) set apacheLocation to objectForKey_("apacheLocation") as text if apacheLocation is "" then pathApache's setStringValue:(do shell script "source $HOME/.bash_profile; which apachectl") else pathApache's setStringValue: objectForKey_("apacheLocation") end if end tell
on configOK_(sender) set apacheLocation to pathApache's StringValue() as text end configOK_
on applicationShouldTerminate_(sender) tell standardUserDefaults() of current application's NSUserDefaults setObject_forKey_(apacheLocation, "apacheLocation") end tell
这是App:D顺便说一下: my little nasty app