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  

Here is a screen shot of the UI http://imgur.com/8xO9K4c

I would like to put a green light if the state is turned on. Any help on this would be great! There are two more buttons here, but I omitted them because I had "Too much code" in my post and stackoverflow would not let me post it.

Thanks in advance!

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