ステータスバーアイテムを作成してメニューバー上にメニューを出し、デスクトップ・スクリーンセーバーのコントロールを行うAppleScriptです。
ステータスバーアイテムを使って、簡単なメニュー操作を行うAppleScriptの試作品です。メニュー操作の方がメインで、デスクトップ・スクリーンセーバーの方はオマケです。
AppleScript名:デスクトップ・スクリーンセーバー |
— Created 2017-03-03 by Takaaki Naganoya — Modified 2018-02-15 by Shane Stanley–Thanks!! — Modified 2018-02-15 by Takaaki Naganoya use AppleScript version "2.5" 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 {"Desktop ScreenSaver", "", "Stop", "", "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 10 set prevMenuItem to "" repeat with i in aList set j to contents of i set aClass to (class of j) as string if j is equal to "" then set aMenuItem to (current application’s NSMenuItem’s separatorItem()) (aMenu’s addItem:aMenuItem) else if (aClass = "text") or (aClass = "string") then if j = "Quit" then set aMenuItem to (current application’s NSMenuItem’s alloc()’s initWithTitle:j action:"actionHandler:" keyEquivalent:"") else set aMenuItem to (current application’s NSMenuItem’s alloc()’s initWithTitle:j action:"actionHandler:" keyEquivalent:"") end if (aMenuItem’s setTag:aCount) (aMenuItem’s setTarget:me) (aMenu’s addItem:aMenuItem) set aCount to aCount + 10 copy aMenuItem to prevMenuItem else if aClass = "list" then –Generate Submenu set subMenu to current application’s NSMenu’s new() (aMenuItem’s setSubmenu:subMenu) set subCounter to 1 repeat with ii in j set jj to contents of ii set subMenuItem1 to (current application’s NSMenuItem’s alloc()’s initWithTitle:jj action:"actionHandler:" keyEquivalent:"") (subMenuItem1’s setTarget:me) (subMenuItem1’s setTag:(aCount + subCounter)) (subMenu’s addItem:subMenuItem1) set subCounter to subCounter + 1 end repeat end if end if end repeat return aMenu end createMenu on actionHandler:sender set aTag to tag of sender as string set aTitle to title of sender as string if aTitle is equal to "Quit" then current application’s NSStatusBar’s systemStatusBar()’s removeStatusItem:aStatusItem –tell me to quit else if aTag = "10" then do shell script "/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -background > /dev/null 2>&1 &" else if aTag = "20" then killScreenSaver() of me set curMode to missing value end if end if end actionHandler: on killScreenSaver() set shellText to "killall ScreenSaverEngine" do shell script shellText end killScreenSaver |
More from my site
(Visited 369 times, 1 visits today)