2013-02-08 2 views
0

AppDelegate.applescript는Xcode :이 코코 스크립트 응용 프로그램의 토글 단추를 만들려면 어떻게해야합니까?

-- iTunes Switcher 
-- 
-- Created by admini on 11/13/12. 
-- Copyright (c) 2012 Bdaniels. No rights reserved. 
-- 



script AppDelegate 
    property parent : class "NSObject" 

    on ButtonHandlerActivationOn_(sender) 
     tell application "iTunes" to quit 
     do shell script "/usr/bin/defaults write com.apple.iTunes StoreActivationMode -integer 1" 
     delay 1 
     do shell script "open -a itunes" 
    end ButtonHandlerActivationOn 

    on ButtonHandlerActivationOff_(sender) 
     tell application "iTunes" to quit 
     do shell script "/usr/bin/defaults write com.apple.iTunes StoreActivationMode -integer 0" 
     delay 1 
     do shell script "open -a itunes" 
    end ButtonHandlerActivationOff 




    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_ 

end script 

여기에 내가 상태가 설정되어있는 경우 녹색 빛을 넣어하고자하는 UI http://imgur.com/8xO9K4c

의 스크린 샷이다. 이것에 대한 도움이 될 것입니다! 여기에 두 개의 버튼이 더 있습니다. 그러나 나는 "너무 많은 코드"를 내 게시물에 포함 시켰고 stackoverflow를 사용하여 게시 할 수 없었기 때문에 생략했습니다.

미리 감사드립니다.

답변

0

먼저 이미지가 필요한 녹색 이미지가 필요합니다. 프로젝트에 추가하십시오. 코드에서 나는 그 이름으로 "green.png"를 사용하고 있습니다. 그런 다음 NSImage 메소드에 액세스하고 단추에 이미지를 추가 할 수 있도록 이들을 추가하십시오.

property NSImage : class "NSImage" 
property greenLightButton : missing value 
property greenLightImage : missing value 

다음으로 "사각형"버튼을 창에 추가하십시오. 그러면 이미지가 표시됩니다. 녹색 이미지를 원하는 크기로 만드십시오. 속성 관리자에서 버튼의 경계선을 선택 취소합니다. 이 시점에서 기본적으로 보이지 않습니다. greenLightButton 속성을 해당 버튼에 연결합니다. 다음으로이 코드를 추가하십시오. 아마 당신의 버튼 방법과 applicationWillFinishLaunching의 코드에서 어디 그런

on applicationWillFinishLaunching_(aNotification) 
    set greenLightImage to NSImage's imageNamed_("green.png") 
end applicationWillFinishLaunching_ 

on isActivationOn() 
    set isOn to false 
    try 
     do shell script "/usr/bin/defaults read com.apple.iTunes StoreActivationMode" 
     if result is "1" then set isOn to true 
    end try 
    return isOn 
end isActivationOn 

는, 당신은 ... 이런 식으로 뭔가를 원하는

if (isActivationOn()) then 
    greenLightButton's setImage_(greenLightImage) 
else 
    greenLightButton's setImage_(missing value) 
end 
관련 문제