ステータスバーのじっけん2

AppleScript名:ステータスバーのじっけん2
— Created 2017-03-03 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"

property aStatusItem : missing value

on run
  init() of me
end run

on init()
  set aList to {"Piyomaru", "Software", "", "Takaaki", "Naganoya", "", "Quit"}
  
  
set aStatusItem to current application’s NSStatusBar’s systemStatusBar()’s statusItemWithLength:(current application’s NSVariableStatusItemLength)
  
  
aStatusItem’s setTitle:"🚗"
  
aStatusItem’s setHighlightMode:true
  
aStatusItem’s setMenu:(createMenu(aList) of me)
end init

on createMenu(aList)
  set aMenu to current application’s NSMenu’s alloc()’s init()
  
set aCount to 1
  
  
repeat with i in aList
    set j to contents of i
    
    
if j is not equal to "" then
      
      
if j = "Quit" then
        set aMenuItem to (current application’s NSMenuItem’s alloc()’s initWithTitle:j action:"actionHandler:" keyEquivalent:"")
        
–(aMenuItem’s setKeyEquivalentModifierMask:(current application’s NSControlKeyMask))
      else
        set aMenuItem to (current application’s NSMenuItem’s alloc()’s initWithTitle:j action:"actionHandler:" keyEquivalent:"")
      end if
      
    else
      set aMenuItem to (current application’s NSMenuItem’s separatorItem())
    end if
    (
aMenuItem’s setTarget:me)
    (
aMenuItem’s setTag:aCount)
    (
aMenu’s addItem:aMenuItem)
    
    
if j is not equal to "" then
      set aCount to aCount + 1
    end if
  end repeat
  
  
return aMenu
end createMenu

on actionHandler:sender
  set aTag to tag of sender as integer
  
set aTitle to title of sender as string
  
  
if aTitle is not equal to "Quit" then
    display dialog aTag as string
  else
    current application’s NSStatusBar’s systemStatusBar()’s removeStatusItem:aStatusItem
  end if
end actionHandler:

★Click Here to Open This Script 

Please follow and like us:

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です