0

AppDelegate.applescript

--  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

状態がオンになったら青信号を出したいのですが。これに関するどんな助けも素晴らしいでしょう!ここにはさらに2つのボタンがありますが、投稿に「コードが多すぎます」とスタックオーバーフローで投稿できないため、ボタンを省略しました。

前もって感謝します!

4

1 に答える 1

0

まず、画像、緑色の画像が必要です。それをプロジェクトに追加します。コードでは、名前として「green.png」を使用しています。次に、これらを追加して、NSImageメソッドにアクセスし、ボタンに画像を追加できるようにします。

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

次に、ウィンドウに「正方形」ボタンを追加します。これにより、画像が表示されます。緑の画像に必要なサイズにします。属性インスペクターで、ボタンの「境界線」のチェックを外します。この時点では基本的に見えなくなります。greenLightButtonプロパティをそのボタンに接続します。次に、このコードを追加します。

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

次に、コードのどこでも、おそらくボタンメソッドとapplicationWillFinishLaunchingで、次のようなものが必要です...

if (isActivationOn()) then
   greenLightButton's setImage_(greenLightImage)
else
   greenLightButton's setImage_(missing value)
end
于 2013-02-09T00:24:32.000 に答える