2011-01-28 6 views
0

그래서 'myApp'응용 프로그램이 있고 로그인 할 때 'myApp'를로드하는 환경 설정이 있습니다. 나는 launchd에를 통해이 실행중인 모든 벌금을 가지고응용 프로그램을 실행하고 숨기려면 launchd

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
<plist version="1.0"> 
    <dict> 
    <key>Label</key> 
     <string>com.myAppDomain.myApp</string> 
    <key>ProgramArguments</key> 
     <array> 
     <string>/Applications/myApp.app/Contents/MacOS/myApp</string> 
     </array> 
    <key>RunAtLoad</key> 
     <true/> 
    </dict> 
</plist> 

나는 또한 사용자에게 또한 숨어있는 옵션을 제공하고자 '을 myApp'

나는 bash는 스크립트를 생성하고, ProgramArguments 배열에 추가 시도

#!/bin/sh 

osascript=/usr/bin/osascript 

$osascript -e 'tell application "System Events" to set visible of process "'myApp'" to false' 

exit 0 

그러나이 중 하나가 실행되지 않거나 내 앱이 초기화 될 가능성이 더 높습니다.

내가 쉽게 간과 할 수있는 더 쉬운 방법이 있습니까? 사전에 감사합니다. 사용자가 실행에서 귀하의 응용 프로그램을 숨기도록 선택할 때

답변

1

당신은

[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HideOnLaunch"]; 

를 호출하여 기본 설정을 plist에서 부울을 설정할 수 있습니다.

그런 앱이 launchd에 통해 시작할 때 앱 자체는 applicationDidFinishLaunching:HideOnLaunch 설정을 확인 할 수 있고, 그에 따라 자신을 숨길 수 :

if([[NSUserDefaults standardUserDefaults] boolForKey:@"HideOnLaunch"]){ 
    [[NSApplication sharedApplication] hide:nil]; 
} 

앱을 숨길 수 launchd을하지 마십시오!

또 다른 접근법은 다음과 같습니다. 인수를 Cocoa 프로그램에 쉽게 전달할 수 있습니다. 이 같은 코코아 응용 프로그램을 실행하는 경우, this NSUserDefaults document에 설명 된대로 :

AnApp.app/Contents/MacOS/AnApp -FuBar YES 

은 그럼 당신은 [[NSUserDefaults standardUserDefaults] boolForKey:@"FuBar"]를 통해 값 YES를 얻을 수 있습니다.

따라서 사용자의 취향에 따라 -HideOnLaunch YES 또는 -HideOnLaunch NO을 설정하는 launchd plist를 작성할 수 있습니다.

그래서, 아마도 applicationDidFinishLaunching:에서 앱 위임에,
HideOnLaunch가 설정되어있는 프로그램의 인수 여부에 따라 귀하의 응용 프로그램을 숨 깁니다.

0

감사합니다.

나는 이런 시작 PLIST에 결국 : 나는의 ProgramArguments 키 문자열로 bash는 스크립트를 추가

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
<plist version="1.0"> 
<dict> 
     <key>Label</key> 
    <string>com.myAppDomain.MyApp</string> 
    <key>ProgramArguments</key> 
    <array> 
     <string>/bin/sh</string> 
     <string>-c</string> 
     <string>/Applications/MyApp.app/Contents/MacOS/MyApp -hideOnLogin YES</string> 
    </array> 
    <key>RunAtLoad</key> 
    <true/> 
</dict> 
</plist> 

애플은 다음 PLIST에서와 같이

~/Library/LaunchAgents/com.apple.FTMonitor.plist 

hideOnLogin 키는 launchd plist를 통해서만 액세스 할 수 있으며 myApp가 종료되면 재설정됩니다.나는 또 다른 핵심 "hideOnLoad"에 바인딩 체크 박스를 가지고 있고,이 변경 될 때, 나도에 출시 PLIST를 다시 작성 : 상황에 따라

/Applications/MyApp.app/Contents/MacOS/MyApp -hideOnLogin YES 

또는

/Applications/MyApp.app/Contents/MacOS/MyApp 

.

시작할 때 두 기본값이 모두 true인지 확인합니다. 그렇다면 myApp를 숨 깁니다. [NSApp hide : self];

다시 올바른 방향으로 나를 가리켜 주셔서 감사합니다!

관련 문제